diff --git a/.gitignore b/.gitignore index 0d81a81..b449b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ quickjs -build \ No newline at end of file +build diff --git a/run_benchmarks.sh b/run_benchmarks.sh new file mode 100755 index 0000000..123fc9a --- /dev/null +++ b/run_benchmarks.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +cmake --build build +./build/run_sunspider_like kraken-1.0/ +./build/run_sunspider_like kraken-1.1/ +./build/run_sunspider_like sunspider-1.0/ +./build/run_octane diff --git a/run_octane.c b/run_octane.c index 3db1981..682423d 100644 --- a/run_octane.c +++ b/run_octane.c @@ -23,11 +23,22 @@ */ #include #include +#include +#ifdef NO_INCLUDE_DIR +#include "quickjs.h" +#include "quickjs-libc.h" +#else #include "quickjs/quickjs.h" #include "quickjs/quickjs-libc.h" +#endif + +void Execute(JSContext *ctx, const char *path, const char *filename, int eval_flags) { + char pathname[1024]; + + snprintf(pathname, sizeof pathname, "%s%s", path, filename); + filename = pathname; -void Execute(JSContext *ctx, const char *filename, int eval_flags) { FILE *file = fopen(filename, "r"); /* assumes max test script size */ static char buf[8 << 20]; // 8 MB @@ -73,34 +84,66 @@ void Execute(JSContext *ctx, const char *filename, int eval_flags) { int main(int argc, char **argv) { JSRuntime *rt = JS_NewRuntime(); JSContext *ctx = JS_NewContext(rt); + const char *path = ""; + int argnum = 1; /* system modules */ js_init_module_std(ctx, "std"); /* disable stack limit */ JS_SetMaxStackSize(rt, 0); - Execute(ctx, "octane/base.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/richards.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/deltablue.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/crypto.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/raytrace.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/earley-boyer.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/regexp.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/splay.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/navier-stokes.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/pdfjs.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/mandreel.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/gbemu-part1.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/gbemu-part2.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/code-load.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/box2d.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/zlib.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/zlib-data.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/typescript.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/typescript-input.js", JS_EVAL_TYPE_GLOBAL); - Execute(ctx, "octane/typescript-compiler.js", JS_EVAL_TYPE_GLOBAL); + if (argc > 1) { + size_t len = strlen(argv[1]); + if (len == 0 || argv[1][len - 1] == '/') { + path = argv[1]; + argnum = 2; + } + } + + Execute(ctx, path, "octane/base.js", JS_EVAL_TYPE_GLOBAL); + + static const char *testfile[] = { + "octane/richards.js", + "octane/deltablue.js", + "octane/crypto.js", + "octane/raytrace.js", + "octane/earley-boyer.js", + "octane/regexp.js", + "octane/splay.js", + "octane/navier-stokes.js", + "octane/pdfjs.js", + "octane/mandreel.js", + "octane/gbemu-part1.js", + "octane/gbemu-part2.js", + "octane/code-load.js", + "octane/box2d.js", + "octane/zlib.js", + "octane/zlib-data.js", + "octane/typescript.js", + "octane/typescript-input.js", + "octane/typescript-compiler.js", + }; + int testfile_number = sizeof(testfile) / sizeof(testfile[0]); + + for (int test = 0; test < testfile_number; test++) { + const char *filename = testfile[test]; + if (argc > argnum) { + int found = 0; + for (int i = argnum; i < argc; i++) { + if (strstr(filename, argv[i])) { + found = 1; + break; + } + } + if (!found) { + printf("Skipping %s%s\n", path, filename); + continue; + } + } + Execute(ctx, path, filename, JS_EVAL_TYPE_GLOBAL); + } - Execute(ctx, "run_octane.js", JS_EVAL_TYPE_MODULE); + Execute(ctx, path, "run_octane.js", JS_EVAL_TYPE_MODULE); JS_FreeContext(ctx); diff --git a/run_octane.js b/run_octane.js index 63520e2..f4eb438 100644 --- a/run_octane.js +++ b/run_octane.js @@ -16,7 +16,7 @@ function PrintError(name, error) { function PrintScore(score) { printf("----\n"); - printf("Score (version " + BenchmarkSuite.version + "): " + score); + printf("Score (version " + BenchmarkSuite.version + "): " + score + "\n"); } BenchmarkSuite.RunSuites({ diff --git a/run_sunspider_like.c b/run_sunspider_like.c index 408185b..dada7ae 100644 --- a/run_sunspider_like.c +++ b/run_sunspider_like.c @@ -26,7 +26,11 @@ #include #include +#ifdef NO_INCLUDE_DIR +#include "quickjs.h" +#else #include "quickjs/quickjs.h" +#endif double total = 0;