summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2014-11-13 11:00:04 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2014-11-13 11:00:15 -0800
commit7861d82c6fcfb3f813e642c0f59318eb4f9f5332 (patch)
tree116269e4b4341222530c7acbde6b1b54d3138f4c /src/main.c
parent3c9bdf645958a1c5b71cc9b96a5b711cca14224f (diff)
Added bench.h and inserted timing macros in main.
`make TIMER=1` to build with timings.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c22
1 files changed, 16 insertions, 6 deletions
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 <string.h>
#include <errno.h>
#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);
}
}