aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/bench.h22
-rw-r--r--src/main.c22
3 files changed, 42 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 40efdf4..3c0f610 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,7 @@ set(HEADERS
chunk.h
references.h
debug.h
+ bench.h
utf8.h
scanners.h
inlines.h
@@ -91,3 +92,6 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -pedantic")
endif()
+if($ENV{TIMER})
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1")
+endif($ENV{TIMER})
diff --git a/src/bench.h b/src/bench.h
new file mode 100644
index 0000000..7308197
--- /dev/null
+++ b/src/bench.h
@@ -0,0 +1,22 @@
+#ifndef __BENCH_H__
+#define __BENCH_H__
+#include <stdio.h>
+#include <sys/time.h>
+
+#ifdef TIMER
+float _cmark_start_time;
+float _cmark_end_time;
+
+#define start_timer() \
+ _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)
+
+#else
+#define start_timer()
+#define end_timer(M)
+#endif
+#endif
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);
}
}