-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.js
More file actions
41 lines (33 loc) · 987 Bytes
/
benchmark.js
File metadata and controls
41 lines (33 loc) · 987 Bytes
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
var Self = require('./self'),
microtime = require('microtime');
var COUNT = 0xfffff;
function Proto() {
}
Proto.prototype.method = function () {
};
var SelfClass = Self({
method: function (self) {
}
});
var proto = new Proto(),
self_class = SelfClass();
// Benchmark prototypal oop
var start = microtime.now();
for (var i = 0; i < COUNT; i += 1) {
proto.method();
}
var duration = microtime.now() - start;
console.log('Prototypal:', COUNT / (duration / 1000000), 'ops/sec');
console.log(' ', duration / COUNT * 1000, 'ns/ops');
console.log('');
// Benchmark self
start = microtime.now();
for (var i = 0; i < COUNT; i += 1) {
self_class.method();
}
var s_duration = microtime.now() - start;
console.log('Self: ', COUNT / (s_duration / 1000000), 'ops/sec');
console.log(' ', s_duration / COUNT * 1000, 'ns/ops');
console.log('');
// Ratio
console.log('Proto/Self:', Math.round(duration / s_duration * 10000) / 100, '% efficiency');