-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
37 lines (33 loc) · 1.38 KB
/
index.ts
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
import * as asmdCalc from '../src/lib/calculation';
import * as jsRawCalc from './calc/js-raw-calc';
import * as mathjsCalc from './calc/mathjs-calc';
import * as decimalCalc from './calc/decimal-calc';
import { benchmarkStart } from './benchmark';
function doBenchmark() {
const jsResult = benchmarkStart(jsRawCalc, 'jsRawCalc');
console.log('----------------------------------------');
const asmdResult = benchmarkStart(asmdCalc, 'asmdCalc');
console.log('----------------------------------------');
const mathjsResult = benchmarkStart(mathjsCalc, 'mathjs');
console.log('----------------------------------------');
const decimalResult = benchmarkStart(decimalCalc, 'decimal');
const result = { jsRaw: jsResult, asmd: asmdResult, decimal: decimalResult, mathjs: mathjsResult };
console.log(result);
// print for markdown table
const testTypes = Object.keys(result.jsRaw).filter((k) => k !== 'times');
testTypes.forEach((type) => {
console.log(`\n\`${type}-${result.jsRaw.times}times\`:\n`);
console.log('| type/time |', Object.keys(result).join(' | '), ' |');
console.log(`| --- | --- | --- | --- | --- |`);
['add', 'sub', 'mul', 'div'].forEach((key) => {
console.log(
`| ${key} |`,
Object.values(result)
.map((d) => d[type][key] + 'ms')
.join(' | '),
' | '
);
});
});
}
doBenchmark();