Added timers.

This commit is contained in:
Ulysse Cura 2026-10-09 14:20:44 +02:00
parent 6538e1d7f3
commit 86409fd36d
1 changed files with 20 additions and 46 deletions

View File

@ -11,7 +11,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
clock_t start_time = clock(); clock_t start_time, end_time;
int status = EXIT_FAILURE; int status = EXIT_FAILURE;
@ -38,6 +38,8 @@ int main(int argc, char *argv[])
goto end; goto end;
} }
start_time = clock();
// Strip program file // Strip program file
while(true) while(true)
{ {
@ -73,8 +75,6 @@ int main(int argc, char *argv[])
} }
} }
rewind(stripped_file);
if(fclose(program_file) == EOF) if(fclose(program_file) == EOF)
{ {
program_file = NULL; program_file = NULL;
@ -86,6 +86,8 @@ int main(int argc, char *argv[])
program_file = NULL; program_file = NULL;
rewind(stripped_file);
size_t brackets_pos[BRACKETS_NB_MAX]; size_t brackets_pos[BRACKETS_NB_MAX];
size_t brackets_correspondances[BRACKETS_NB_MAX]; size_t brackets_correspondances[BRACKETS_NB_MAX];
@ -128,7 +130,7 @@ int main(int argc, char *argv[])
if(err) if(err)
{ {
fprintf(stderr, "Error reading file: %d\n", argv[1], ferror(stripped_file)); fprintf(stderr, "Error reading file: %d\n", ferror(stripped_file));
} }
else else
{ {
@ -163,6 +165,10 @@ int main(int argc, char *argv[])
} }
} }
end_time = clock();
fprintf(stderr, "Parsing time : %fs\n", (float)(end_time - start_time) / (float)CLOCKS_PER_SEC);
rewind(stripped_file); rewind(stripped_file);
// Program memory // Program memory
@ -171,6 +177,8 @@ int main(int argc, char *argv[])
size_t bracket_index = 0; size_t bracket_index = 0;
start_time = clock();
while(true) while(true)
{ {
int c = fgetc(stripped_file); int c = fgetc(stripped_file);
@ -195,6 +203,8 @@ int main(int argc, char *argv[])
bracket_index = brackets_correspondances[bracket_index]; bracket_index = brackets_correspondances[bracket_index];
fseek(stripped_file, brackets_pos[bracket_index], SEEK_SET); fseek(stripped_file, brackets_pos[bracket_index], SEEK_SET);
} }
bracket_index++;
} }
else if(c == '>') else if(c == '>')
{ {
@ -215,48 +225,16 @@ int main(int argc, char *argv[])
else if(c == '.') else if(c == '.')
{ {
putchar(mem[mem_pointer]); putchar(mem[mem_pointer]);
fflush(stdout);
} }
else if(c == ',') else if(c == ',')
{ {
/*
static int next_input = -1;
int input;
if(next_input != -1)
{
input = next_input;
next_input = -1;
}
else
{
input = getchar();
}
next_input = getchar();
if(input != '\n')
{
mem[mem_pointer] = input;
}
else
{
if(next_input == '\n')
{
mem[mem_pointer] = '\n';
}
next_input = -1;
}
*/
mem[mem_pointer] = getchar(); mem[mem_pointer] = getchar();
} }
}
if(c == '[' || c == ']') end_time = clock();
{
bracket_index++; fprintf(stderr, "\nExecution time : %fs\n", (float)(end_time - start_time) / (float)CLOCKS_PER_SEC);
}
}
status = EXIT_SUCCESS; status = EXIT_SUCCESS;
@ -265,7 +243,7 @@ end:
{ {
if(fclose(stripped_file)) if(fclose(stripped_file))
{ {
fprintf(stderr, "Failed to close tmp file: %d\n", errno); fprintf(stderr, "Error closing tmp file: %d\n", errno);
} }
} }
@ -273,13 +251,9 @@ end:
{ {
if(fclose(program_file)) if(fclose(program_file))
{ {
fprintf(stderr, "Failed to close tmp file: %d\n", errno); fprintf(stderr, "Error closing tmp file: %d\n", errno);
} }
} }
clock_t end_time = clock();
fprintf(stderr, "\nExecution time : %fs\n", (float)(end_time - start_time) / (float)CLOCKS_PER_SEC);
return status; return status;
} }