node/benchmark/function_call/bench.js

36 lines
554 B
JavaScript
Raw Normal View History

2010-09-24 10:55:26 +08:00
var binding = require('./build/default/binding');
2010-09-24 17:21:17 +08:00
c = 0
2010-09-24 10:55:26 +08:00
function js() {
2010-09-24 17:21:17 +08:00
return c++; //(new Date()).getTime();
2010-09-24 10:55:26 +08:00
}
var cxx = binding.hello;
2010-09-24 17:21:17 +08:00
var i, N = 100000000;
2010-09-24 10:55:26 +08:00
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));