tests performance of nested, recursive calls in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Tests perfromance of deeply nested calls in C
#define TRACK_LIM 3000
int func_a(const char* data, int* tracker)
{
//printf("count: %d\n", (*tracker += 1));
*tracker += 1;
void* g = malloc(8);
if(*tracker == TRACK_LIM) return 2;
switch(*data)
{
case 'f':
case 'g':
case '7':
case '3':
case '&':
case '!':
case '@':
case '?':
case '%':
case '*':
free(g);
return 1 + func_a(data, tracker);
default:
return 1;
}
}
int main(){
const char* mes = "&&&&&&&";
int trck = 0;
clock_t start, end;
start = clock();
func_a(mes, &trck);
end = clock();
printf( "Number of seconds: %f\n", (end-start)/(double)CLOCKS_PER_SEC );
return 0;
}