forked from tjanczuk/edge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarks-direct.js
74 lines (62 loc) · 2.21 KB
/
benchmarks-direct.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var edge = require('edge');
var fs = require('fs');
var async = require('async');
var edgeInvoke = edge.func('bin/Release/Echo.dll');
var nodeInvoke = function(input, cb) {
cb(null, input);
};
var TIMES = 10000;
var str1 = fs.readFileSync("row-1.txt"),
str10 = fs.readFileSync("row-10.txt"),
str100 = fs.readFileSync("row-100.txt"),
json1 = JSON.parse(str1),
json10 = JSON.parse(str10),
json100 = JSON.parse(str100);
var fns = [];
function run(fn, times, cb) {
var start = Date.now();
var called = 0;
for (var i = 0; i < times; i++) {
fn(function() {
if (++called == times) {
var takenMs = Date.now() - start;
cb(takenMs);
}
});
}
}
function bench(nodeFn, edgeFn, msg, cb) {
console.log("running " + msg + "...\n");
run(nodeFn, TIMES, function(nodeTakenMs) {
run(edgeFn, TIMES, function (edgeTakenMs) {
console.log(msg + " " + TIMES + " times: ");
console.log("node: " + nodeTakenMs + "ms");
console.log("edge: " + edgeTakenMs + "ms");
console.log((edgeTakenMs > nodeTakenMs ? "edge" : "node") + " is " +
Math.round(Math.max(nodeTakenMs, edgeTakenMs) / Math.min(nodeTakenMs, edgeTakenMs), 3) + "x slower\n");
cb();
});
});
}
var nodeWith = function(input) {
return function(cb) {
nodeInvoke(input, function(err, result) {
cb();
});
};
};
var edgeWith = function(input) {
return function(cb) {
edgeInvoke(input, function(err, result) {
cb();
});
};
};
async.series([
function (cb) { bench(nodeWith(str1), edgeWith(str1), "1 Northwind Customer.txt", cb); },
function (cb) { bench(nodeWith(str10), edgeWith(str10), "10 Northwind Customer.txt", cb); },
function (cb) { bench(nodeWith(str100), edgeWith(str100), "100 Northwind Customer.txt", cb); },
function (cb) { bench(nodeWith(json1), edgeWith(json1), "1 Northwind Customer.json", cb); },
function (cb) { bench(nodeWith(json10), edgeWith(json10), "10 Northwind Customer.json", cb); },
function (cb) { bench(nodeWith(json100), edgeWith(json100), "100 Northwind Customer.json", cb); }
]);