From 7861d82c6fcfb3f813e642c0f59318eb4f9f5332 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 13 Nov 2014 11:00:04 -0800 Subject: Added bench.h and inserted timing macros in main. `make TIMER=1` to build with timings. --- src/main.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 2bfe291..1e3a6b3 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ #include #include #include "cmark.h" +#include "bench.h" void print_usage() { @@ -25,6 +26,19 @@ static void print_document(node_block *document, bool ast) } } +void parse_and_render(node_block *document, FILE *fp, bool ast) +{ + start_timer(); + document = cmark_parse_file(fp); + end_timer("cmark_parse_file"); + start_timer(); + print_document(document, ast); + end_timer("print_document"); + start_timer(); + cmark_free_blocks(document); + end_timer("free_blocks"); +} + int main(int argc, char *argv[]) { int i, numfps = 0; @@ -52,9 +66,7 @@ int main(int argc, char *argv[]) } if (numfps == 0) { - document = cmark_parse_file(stdin); - print_document(document, ast); - cmark_free_blocks(document); + parse_and_render(document, stdin, ast); } else { for (i = 0; i < numfps; i++) { FILE *fp = fopen(argv[files[i]], "r"); @@ -65,9 +77,7 @@ int main(int argc, char *argv[]) exit(1); } - document = cmark_parse_file(fp); - print_document(document, ast); - cmark_free_blocks(document); + parse_and_render(document, fp, ast); fclose(fp); } } -- cgit v1.2.3