-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbenchmark.js
More file actions
43 lines (40 loc) · 1.31 KB
/
benchmark.js
File metadata and controls
43 lines (40 loc) · 1.31 KB
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
const Benchmark = require('benchmark');
const ProceduralLambda = require('./procedural-lambda');
const L = require('list/methods');
function runTestsForN(n){
function* generator(){
for(let i = 0; i < n; i++)
yield i;
}
const m1 = (v) => v*2;
const f1 = (v) => v % 4 === 0;
const r1 = (accum,v) => accum+v;
const r1i = (accum,v,i) => accum+v;
let suite;
let packed = [...generator()];
let lbd = (new ProceduralLambda(packed)).map(m1).filter(f1).reduce(r1, 0);
let lbdi = (new ProceduralLambda(packed)).map(m1).filter(f1).reduce(r1i, 0);
let lbdc = (new ProceduralLambda(packed)).mapComplex(m1).filterComplex(f1).reduceComplex(r1, 0);
let list = L.list(packed);
suite = new Benchmark.Suite('Map Filter Length');
suite
.add('raw', () => packed.map(m1).filter(f1).reduce(r1, 0))
.add('list', () => list.map(m1).filter(f1).reduce(r1, 0))
.add('lambda-using-complex', () => lbdc.execute())
.add('lambda-with-indices', () => lbdi.execute())
.add('lambda', () => lbd.execute())
.on('cycle', (ev) => {
console.log(String(ev.target));
})
.on('complete', function() {
console.log(`Fastest execution for N=${n} is ${this.filter('fastest').map('name')}\n`);
})
.run();
}
runTestsForN(10);
runTestsForN(100);
runTestsForN(1000);
runTestsForN(10000);
runTestsForN(100000);
runTestsForN(1000000);
runTestsForN(10000000);