From 84cd1538ee20b934c6892f38578a08106a934fe8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 4 Aug 2009 19:46:42 -0700 Subject: Integrated benchmarks into main Makefile. --- benchmarks/main.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 benchmarks/main.c (limited to 'benchmarks/main.c') diff --git a/benchmarks/main.c b/benchmarks/main.c new file mode 100644 index 0000000..f66b4d0 --- /dev/null +++ b/benchmarks/main.c @@ -0,0 +1,46 @@ + +#include +#include +#include +#include +#include + +static bool initialize(); +static void cleanup(); +static size_t run(); + +int main (int argc, char *argv[]) +{ + (void)argc; + + /* Change cwd to where the binary is. */ + char *lastslash = strrchr(argv[0], '/'); + char *progname = argv[0]; + if(lastslash) { + *lastslash = '\0'; + chdir(argv[0]); + *lastslash = '/'; + progname = lastslash + 3; /* "/b_" */ + } + + if(!initialize()) { + fprintf(stderr, "%s: failed to initialize\n", argv[0]); + return 1; + } + + size_t total_bytes = 0; + clock_t before = clock(); + for(int i = 0; true; i++) { + if((i & 0xFF) == 0 && (clock() - before > CLOCKS_PER_SEC)) break; + size_t bytes = run(); + if(bytes == 0) { + fprintf(stderr, "%s: failed.\n", argv[0]); + return 2; + } + total_bytes += bytes; + } + double elapsed = ((double)clock() - before) / CLOCKS_PER_SEC; + printf("%s:%d\n", progname, (int)(total_bytes / elapsed / (1 << 20))); + cleanup(); + return 0; +} -- cgit v1.2.3