cmark

My personal build of CMark ✏️

Commit
5a8f1acf888c60463e7b418d55c1a5d26b3799f1
Parent
5cbede7a725b8b72779a5a4bd38d49a2d01fc022
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

Moved the timing macros to get finer-grained information.

Diffstat

3 files changed, 9 insertions, 3 deletions

Status File Name N° Changes Insertions Deletions
Modified src/bench.h 5 4 1
Modified src/blocks.c 5 5 0
Modified src/main.c 2 0 2
diff --git a/src/bench.h b/src/bench.h
@@ -6,14 +6,17 @@
 #ifdef TIMER
 float _cmark_start_time;
 float _cmark_end_time;
+float _cmark_save_time;
 
 #define start_timer() \
+	_cmark_save_time = _cmark_start_time; \
 	_cmark_start_time = (float)clock()/CLOCKS_PER_SEC
 
 #define end_timer(M) \
 	_cmark_end_time = (float)clock()/CLOCKS_PER_SEC; \
 	fprintf(stderr, "[TIME] (%s:%d) %8.f ns " M "\n", __FILE__, \
-		__LINE__, (_cmark_end_time - _cmark_start_time) * 1000000)
+		__LINE__, (_cmark_end_time - _cmark_start_time) * 1000000); \
+	_cmark_start_time = _cmark_save_time;
 
 #else
 #define start_timer()
diff --git a/src/blocks.c b/src/blocks.c
@@ -9,6 +9,7 @@
 #include "scanners.h"
 #include "inlines.h"
 #include "html/houdini.h"
+#include "bench.h"
 
 #define peek_at(i, n) (i)->data[n]
 
@@ -378,6 +379,7 @@ static int lists_match(struct ListData *list_data, struct ListData *item_data)
 
 static node_block *finalize_document(node_block *document, int linenum)
 {
+	start_timer();
 	while (document != document->top) {
 		finalize(document, linenum);
 		document = document->parent;
@@ -385,6 +387,7 @@ static node_block *finalize_document(node_block *document, int linenum)
 
 	finalize(document, linenum);
 	process_inlines(document, document->as.document.refmap);
+	end_timer("finalize_document");
 
 	return document;
 }
@@ -396,12 +399,14 @@ extern node_block *cmark_parse_file(FILE *f)
 	int linenum = 1;
 	node_block *document = make_document();
 
+	start_timer();
 	while (fgets((char *)buffer, sizeof(buffer), f)) {
 		utf8proc_detab(&line, buffer, strlen((char *)buffer));
 		incorporate_line(&line, linenum, &document);
 		strbuf_clear(&line);
 		linenum++;
 	}
+	end_timer("incorporate_line(s)");
 
 	strbuf_free(&line);
 	return finalize_document(document, linenum);
diff --git a/src/main.c b/src/main.c
@@ -28,9 +28,7 @@ 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");