Skip to content

Commit da36298

Browse files
committed
benchmark in browser: 5 seconds instead of 10
1 parent 7cb3a87 commit da36298

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

benchmark/browser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
export default async function exec(benchmark, mode) {
3+
export default async function exec(benchmark, mode, time) {
44
let SVM;
55
if(mode === 'asm') {
66
SVM = await import('../asm');
@@ -10,8 +10,8 @@ export default async function exec(benchmark, mode) {
1010
throw new Error('Invalid mode');
1111
}
1212

13-
const count = benchmark(SVM);
14-
console.log(`${mode}: ${count} iterations.`);
13+
const count = benchmark(SVM, time);
14+
console.log(`${mode}: ${count} iterations in ${time} seconds.`);
1515

1616
return count;
1717
}

demos/components/Benchmark.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ export default class Benchmarks extends Component {
77
this.state = {};
88
}
99
async onRun() {
10-
const asmTime = await runBenchmark(this.props.benchmark, 'asm');
10+
const asmTime = await runBenchmark(this.props.benchmark, 'asm', 5);
1111
this.setState({
1212
asmTime
1313
});
14-
const wasmTime = await runBenchmark(this.props.benchmark, 'wasm');
14+
15+
await wait();
16+
17+
const wasmTime = await runBenchmark(this.props.benchmark, 'wasm', 5);
1518
this.setState({
1619
wasmTime
1720
});
@@ -27,3 +30,9 @@ export default class Benchmarks extends Component {
2730
)
2831
}
2932
}
33+
34+
function wait() {
35+
return new Promise(resolve => {
36+
setTimeout(resolve, 0);
37+
});
38+
}

0 commit comments

Comments
 (0)