Skip to content

Commit 5f54713

Browse files
MaxGraeydcodeIO
authored andcommitted
Update nbody example for Rust (AssemblyScript#528)
1 parent f841f0f commit 5f54713

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

examples/n-body/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ Benchmark
3232
***Environment:***
3333
- MacBook Pro (Retina, 15-inch, Late 2013)
3434
- macOS 10.14.3
35-
- node.js v11.9.0
36-
- rustc 1.33.0-nightly (ceb251214 2019-01-16)
35+
- node.js v11.10.1
36+
- rustc 1.35.0-nightly (a9da8fc9c 2019-03-04)
3737

3838
***Results:***
3939

4040
| Target | Time, ***ms*** | Size, ***KB*** |
4141
|-------------------------|-----------------|----------------|
42-
| **AssemblyScript WASM** | **2901** | **2** |
43-
| AssemblyScript ASMJS | 3720 | 19* |
44-
| JavaScript | 2716 | 5* |
45-
| Rust WASM | 2883 | 13 |
42+
| **AssemblyScript WASM** | **2921** | **2** |
43+
| AssemblyScript ASMJS | 3807 | 19* |
44+
| JavaScript | 2757 | 5* |
45+
| Rust WASM | 2866 | 20 / 2** |
4646

4747
___* unminified___
48+
49+
___** after wasm-gc___

examples/n-body/build/rust.optimized.wasm

100755100644
-10.7 KB
Binary file not shown.

examples/n-body/rust/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/n-body/rust/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Build
22

33
```bash
4-
cargo build --release --target=wasm32-unknown-unknown
4+
cargo +nightly build --release --target wasm32-unknown-unknown
55
```
66

7-
***Next step optimize target wasm via wasm-opt.***
7+
***Next step optimize target wasm via wasm-gc***

examples/n-body/rust/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const compiled = new WebAssembly.Module(
88
const imports = {
99
env: {
1010
memory: new WebAssembly.Memory({ initial: 17 }),
11-
abort: (filename, line, column) => {
12-
throw Error("abort called at " + line + ":" + colum);
11+
abort: (_filename, line, column) => {
12+
throw Error("abort called at " + line + ":" + column);
1313
}
1414
}
1515
};

examples/n-body/rust/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code adopted from https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-rust-1.html
22

3-
#![feature(core_intrinsics, panic_implementation)]
3+
#![feature(core_intrinsics)]
44
#![no_std]
55

66
use core::intrinsics;
@@ -156,18 +156,18 @@ fn offset_momentum(bodies: &mut [Planet; N_BODIES]) {
156156
}
157157

158158
#[no_mangle]
159-
pub unsafe extern "C" fn init() {
159+
pub unsafe extern fn init() {
160160
offset_momentum(&mut BODIES);
161161
}
162162

163163
#[no_mangle]
164-
pub unsafe extern "C" fn step() -> f64 {
164+
pub unsafe extern fn step() -> f64 {
165165
advance(&mut BODIES, 0.01);
166166
energy(&BODIES)
167167
}
168168

169169
#[no_mangle]
170-
pub unsafe extern "C" fn bench(steps: i32) {
170+
pub unsafe extern fn bench(steps: i32) {
171171
for _ in 0..steps {
172172
advance(&mut BODIES, 0.01);
173173
}

0 commit comments

Comments
 (0)