-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed.js
33 lines (25 loc) · 919 Bytes
/
speed.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
'use strict';
const { Univariate } = require( '../index.js' );
const perf = new Univariate({precision: 1e-10});
const measurements = 100;
const points = Number.parseInt(process.argv[2] ?? 0) || 1000;
for (let i = 0; i < measurements; i++) {
const t0 = new Date();
const stat = new Univariate();
for (let j = 0; j < points; j++)
stat.add(j);
stat.mean();
stat.stdev();
for (let j = 0; j <= 100; j+= 10)
stat.percentile(j);
stat.histogram();
perf.add( (new Date() - t0) / points );
}
const hist = perf.histogram({count:16, scale:70})
.map( x => perf.shorten(x[1], x[2])+'\t'+'+'.repeat(x[0]) )
.join('\n');
console.log(hist);
console.log( 'average: ', perf.neat.mean(), ' +- ', perf.neat.stdev(), ' ms per data point');
console.log( 'median: ', perf.neat.median() );
console.log( '90%: ', perf.neat.percentile(90) );
console.log(JSON.stringify(perf));