Skip to content

Commit 4e1bcdc

Browse files
committed
bench: Add function_call to bench-misc
1 parent e87ed91 commit 4e1bcdc

File tree

7 files changed

+46
-61
lines changed

7 files changed

+46
-61
lines changed

benchmark/function_call/bench.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

benchmark/function_call/wscript

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
binding:
2+
node-gyp rebuild --nodedir=../../..
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#include <v8.h>
22
#include <node.h>
3-
#include <time.h>
43

54
using namespace v8;
65

76
static int c = 0;
87

98
static Handle<Value> Hello(const Arguments& args) {
109
HandleScope scope;
11-
//time_t tv = time(NULL);
1210
return scope.Close(Integer::New(c++));
1311
}
1412

1513
extern "C" void init (Handle<Object> target) {
1614
HandleScope scope;
17-
//target->Set(String::New("hello"), String::New("World"));
1815
NODE_SET_METHOD(target, "hello", Hello);
1916
}
17+
18+
NODE_MODULE(binding, init);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ]
6+
}
7+
]
8+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// show the difference between calling a short js function
2+
// relative to a comparable C++ function.
3+
// Reports millions of calls per second.
4+
// Note that JS speed goes up, while cxx speed stays about the same.
5+
6+
var assert = require('assert');
7+
var common = require('../../common.js');
8+
9+
var binding = require('./build/Release/binding');
10+
var cxx = binding.hello;
11+
12+
var c = 0;
13+
function js() {
14+
return c++;
15+
}
16+
17+
assert(js() === cxx());
18+
19+
var bench = common.createBenchmark(main, {
20+
type: ['js', 'cxx'],
21+
millions: [1,10,50]
22+
});
23+
24+
function main(conf) {
25+
var n = +conf.millions * 1e6;
26+
27+
var fn = conf.type === 'cxx' ? cxx : js;
28+
bench.start();
29+
for (var i = 0; i < n; i++) {
30+
fn();
31+
}
32+
bench.end(+conf.millions);
33+
}

0 commit comments

Comments
 (0)