forked from ddmills/js-ecs-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
83 lines (61 loc) · 2.12 KB
/
index.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
75
76
77
78
79
80
81
82
83
import * as libs from './libraries';
import * as suts from './suites';
import elegantSpinner from 'elegant-spinner';
import logUpdate from 'log-update';
const libraries = Object.values(libs);
const suites = Object.values(suts);
const now = () => {
const hr = process.hrtime();
return (hr[0] * 1e9 + hr[1]) / 1000;
};
const frame = elegantSpinner();
suites.forEach((suite) => {
const output = [];
libraries.forEach((library, libIdx) => {
suite.setup(library);
let sum = 0;
for (let i = 0; i < suite.iterations; i++) {
const start = now();
suite.perform(library);
sum += now() - start;
if (i % 200 === 0) {
const progress = (i / suite.iterations) * 100;
const lib = `${libIdx}/${libraries.length}`;
logUpdate(
`${frame()} ${suite.name} - ${lib} ${
library.name
} ${progress.toFixed(0)}%`
);
}
}
const updates = library.geMovementSystemUpdateCount();
output.push({
library,
sum,
updates,
});
library.cleanup();
});
logUpdate.clear();
output.sort((o1, o2) => o1.sum - o2.sum);
console.log(`Suite ${suite.name} (${suite.iterations} iterations)`);
output.forEach((out) => {
const avg = Math.round(out.sum / suite.iterations);
const percent = (out.sum / output[0].sum) * 100 - 100;
const nameTxt = out.library.name.padEnd(12, ' ');
const sumTxt = `${Math.round(out.sum)}`.padStart(10, ' ') + 'ms';
const avgText = `${avg}`.padStart(6, ' ') + 'ms';
const updateText =
out.updates > 0 ? `${out.updates} updates`.padStart(16) : '';
let percentText = percent.toFixed(1).padStart(10, ' ') + '%';
if (percent <= 0) {
percentText += ' fastest';
} else {
percentText += ' slower';
}
console.log(
` - ${nameTxt}${avgText}${sumTxt}${updateText}${percentText}`
);
});
console.log('');
});