forked from ddmills/js-ecs-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (79 loc) · 2.6 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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) => {
if (!library.suites.includes(suite.name)) {
output.push({
library,
sum: Infinity,
updates: 0,
skipped: true,
});
return;
}
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.getMovementSystemUpdateCount();
output.push({
library,
sum,
updates,
skipped: false,
});
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;
let nameTxt = out.library.name.padEnd(12, ' ');
let sumTxt = `${Math.round(out.sum)}`.padStart(10, ' ') + 'ms';
let avgText = `${avg}`.padStart(6, ' ') + 'ms';
let updateText =
out.updates > 0 ? `${out.updates} updates`.padStart(20) : '';
let percentText = percent.toFixed(1).padStart(10, ' ') + '%';
if (percent <= 0) {
percentText += ' fastest';
} else {
percentText += ' slower';
}
if (out.skipped) {
sumTxt = '';
avgText = '';
updateText = '';
updateText = '';
percentText = '';
nameTxt = nameTxt.padEnd(44, ' ') + 'skipped';
}
console.log(
` - ${nameTxt}${avgText}${sumTxt}${updateText}${percentText}`
);
});
console.log('');
});