diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 53 |
1 files changed, 17 insertions, 36 deletions
@@ -3,54 +3,29 @@ #include "utils/file.h" #include "utils/log.h" #include <stdio.h> -#include <time.h> - -// #define PRINT_COMPILE_TREE -// #define PRINT_STATISTICS #ifdef PRINT_STATISTICS -static struct timespec diff(struct timespec end, struct timespec start) { - struct timespec temp; - if ((end.tv_nsec - start.tv_nsec) < 0) { - temp.tv_sec = end.tv_sec - start.tv_sec - 1; - temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec; - } else { - temp.tv_sec = end.tv_sec - start.tv_sec; - temp.tv_nsec = end.tv_nsec - start.tv_nsec; - } - return temp; -} - -static struct timespec add(struct timespec left, struct timespec right) { - struct timespec result; - result.tv_nsec = left.tv_nsec + right.tv_nsec; - result.tv_sec = (left.tv_sec + right.tv_sec) + result.tv_nsec / 1000000000; - result.tv_nsec %= 1000000000; - return result; -} - -static void printTime(struct timespec time) { - printf("%02ld:%02ld.%06ldus", time.tv_sec / 60, time.tv_sec % 60, - time.tv_nsec / 1000); -} +#include "utils/time.h" #endif static int run(const char *filePath) { #ifdef PRINT_STATISTICS struct timespec start, end; + struct timespec lexTime = {0}; + struct timespec parseTime = {0}; struct timespec astTime; struct timespec runTime; struct timespec totalTime = {0}; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); #endif - AstTreeRoots astTrees = makeAstTree(filePath); + AstTreeRoots astTrees = makeAstTree(filePath, &lexTime, &parseTime); if (astTrees.size == AST_TREE_ROOTS_ERROR.size) { return 1; } #ifdef PRINT_STATISTICS clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); - astTime = diff(end, start); - totalTime = add(totalTime, astTime); + astTime = time_diff(end, start); + totalTime = time_add(totalTime, astTime); #endif #ifdef PRINT_COMPILE_TREE for (size_t i = 0; i < astTrees.size; ++i) { @@ -70,17 +45,23 @@ static int run(const char *filePath) { astTreeRootsDestroy(astTrees); #ifdef PRINT_STATISTICS clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); - runTime = diff(end, start); - totalTime = add(totalTime, runTime); + runTime = time_diff(end, start); + totalTime = time_add(totalTime, runTime); #endif #ifdef PRINT_STATISTICS + astTime = time_diff(astTime, parseTime); + parseTime = time_diff(parseTime, lexTime); + printf("\nlexTime: "); + time_print(lexTime); + printf("\nparseTime: "); + time_print(parseTime); printf("\nastTime: "); - printTime(astTime); + time_print(astTime); printf("\nrunTime: "); - printTime(runTime); + time_print(runTime); printf("\ntotal: "); - printTime(totalTime); + time_print(totalTime); printf("\n"); #endif |