diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-09-24 06:55:26 +0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-09-24 09:27:44 +0400 |
commit | 3fc9192d0dda254888268093ab6693290d89344c (patch) | |
tree | 36aa86a3c104c2a9b34a888afc0c29555fc55264 /benchmark | |
parent | 5535aa3d51c6af2380540bb5f0908357b76ebd13 (diff) |
Add function_call benchmark
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/function_call/bench.js | 33 | ||||
-rw-r--r-- | benchmark/function_call/binding.cc | 17 | ||||
-rw-r--r-- | benchmark/function_call/wscript | 15 |
3 files changed, 65 insertions, 0 deletions
diff --git a/benchmark/function_call/bench.js b/benchmark/function_call/bench.js new file mode 100644 index 00000000000..39f76caebc7 --- /dev/null +++ b/benchmark/function_call/bench.js @@ -0,0 +1,33 @@ +var binding = require('./build/default/binding'); + +function js() { + return (new Date()).getTime(); +} + +var cxx = binding.hello; + +var i, N = 10000000; + +console.log(js()); +console.log(cxx()); + + + +var start = new Date(); +for (i = 0; i < N; i++) { + js(); +} +var jsDiff = new Date() - start; +console.log(N +" JS function calls: " + jsDiff); + + +var start = new Date(); +for (i = 0; i < N; i++) { + cxx(); +} +var cxxDiff = new Date() - start; +console.log(N +" C++ function calls: " + cxxDiff); + +console.log("\nJS speedup " + (cxxDiff / jsDiff)); + + diff --git a/benchmark/function_call/binding.cc b/benchmark/function_call/binding.cc new file mode 100644 index 00000000000..e33d5900cb0 --- /dev/null +++ b/benchmark/function_call/binding.cc @@ -0,0 +1,17 @@ +#include <v8.h> +#include <node.h> +#include <time.h> + +using namespace v8; + +static Handle<Value> Hello(const Arguments& args) { + HandleScope scope; + time_t tv = time(NULL); + return scope.Close(Integer::New(tv)); +} + +extern "C" void init (Handle<Object> target) { + HandleScope scope; + //target->Set(String::New("hello"), String::New("World")); + NODE_SET_METHOD(target, "hello", Hello); +} diff --git a/benchmark/function_call/wscript b/benchmark/function_call/wscript new file mode 100644 index 00000000000..3db367fe0e5 --- /dev/null +++ b/benchmark/function_call/wscript @@ -0,0 +1,15 @@ +srcdir = '.' +blddir = 'build' +VERSION = '0.0.1' + +def set_options(opt): + opt.tool_options('compiler_cxx') + +def configure(conf): + conf.check_tool('compiler_cxx') + conf.check_tool('node_addon') + +def build(bld): + obj = bld.new_task_gen('cxx', 'shlib', 'node_addon') + obj.target = 'binding' + obj.source = 'binding.cc' |