4 ms·
The Rust vs. Go comparison has two key differences: - The Rust example uses 8 bit unsigned ints vs. Go example uses 32 bit signed ints - Rust's sort is stable
by ankrgyl 4y ago
The Rust vs. Go comparison has two key differences:
- The Rust example uses 8 bit unsigned ints vs. Go example uses 32 bit signed ints
- Rust's sort is stable by default whereas Go's is not.
If you tweak the Rust benchmark to use `i32` instead of `u8` and `sort_unstable` instead of `sort`, you should see ~3-4x faster performance.
- zRedShift 4y agoMade a PR with the fixes, Rust is now 3 times faster than tinygo, and the wasm is almost 3 times smaller (wasm+js is twice as small) as expected. https://github.com/Ecostack/wasm-rust-go-asc/pull/1 https://github.com/Ecostack/wasm-rust-go-asc/pull/1 My first foray into wasm, so I probably missed some optimizations like wasm-opt.
- twp 4y agoThe Go version should also use `sort.Ints`. https://pkg.go.dev/sort#Ints https://pkg.go.dev/sort#Ints
- miohtama 4y agoAlso I would assume different languages have different random() implementations which could contribute to the run time. So to make tests equal, you should not measure time to set up the array.