Skip to content

Commit 206e4c4

Browse files
MaxGraeydcodeIO
authored andcommitted
Improve n-body bench env (AssemblyScript#457)
1 parent 8d2194f commit 206e4c4

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

examples/n-body/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ Benchmark
3131

3232
***Environment:***
3333
- MacBook Pro (Retina, 15-inch, Late 2013)
34-
- macOS 10.14
35-
- node.js v10.11.0
36-
- rustc 1.31.0-nightly (4bd4e4130 2018-10-25)
34+
- macOS 10.14.3
35+
- node.js v11.9.0
36+
- rustc 1.33.0-nightly (ceb251214 2019-01-16)
3737

3838
***Results:***
3939

4040
| Target | Time, ***ms*** | Size, ***KB*** |
4141
|-------------------------|-----------------|----------------|
42-
| **AssemblyScript WASM** | **3167** | **2** |
43-
| AssemblyScript ASMJS | 3633 | 21* |
44-
| JavaScript | 2628 | 5* |
45-
| Rust WASM | 3876 | 13 |
42+
| **AssemblyScript WASM** | **2901** | **2** |
43+
| AssemblyScript ASMJS | 3720 | 19* |
44+
| JavaScript | 2716 | 5* |
45+
| Rust WASM | 2883 | 13 |
4646

4747
___* unminified___

examples/n-body/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build",
1111
"build": "npm run asbuild && npm run tsbuild",
1212
"server": "http-server . -o -c-1",
13-
"test": "node tests"
13+
"test": "node --noliftoff --nowasm-tier-up --wasm-lazy-compilation --wasm-no-bounds-checks --expose-gc tests"
1414
},
1515
"devDependencies": {
1616
"http-server": "^0.11.1",

examples/n-body/tests/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,25 @@ const nbodyJS = new Function(
3434
...Object.keys(scopeJS).concat(src + "\nreturn exports"))(...Object.values(scopeJS)
3535
);
3636

37+
function gcCollect() {
38+
if (global.gc) {
39+
global.gc();
40+
global.gc();
41+
}
42+
}
43+
44+
function sleep(delay) {
45+
var start = Date.now();
46+
while (Date.now() < start + delay);
47+
}
48+
3749
function test(nbody, steps) {
3850
nbody.init();
3951
var start = process.hrtime();
4052
nbody.bench(steps);
41-
return process.hrtime(start);
53+
let t = process.hrtime(start);
54+
gcCollect();
55+
return t;
4256
}
4357

4458
var steps = process.argv.length > 2 ? parseInt(process.argv[2], 10) : 20000000;
@@ -66,6 +80,7 @@ prologue("Rust WASM", steps);
6680
epilogue(test(nbodyRS, steps));
6781

6882
console.log("\nWARMED UP SERIES:\n");
83+
sleep(1000);
6984

7085
prologue("AssemblyScript WASM", steps);
7186
epilogue(test(nbodyAS, steps));

0 commit comments

Comments
 (0)