Here is a simple example of using wasm-bindgen to call Rust functions from JavaScript.
This file (wasm-bind-demo/index.js at e37f8359b291a090341f3684515ee908e238616f · mvolkmann/wasm-bind-demo · GitHub) creates an array of 10 million random floating point numbers in a Float64Array
.
It then calls a Rust function (wasm-bind-demo/lib.rs at e37f8359b291a090341f3684515ee908e238616f · mvolkmann/wasm-bind-demo · GitHub) to sum them, tracking the milliseconds required.
Then it does the same using a JavaScript function (wasm-bind-demo/index.js at e37f8359b291a090341f3684515ee908e238616f · mvolkmann/wasm-bind-demo · GitHub).
The Rust function takes about 10 times as long to run. Is there a more efficient way to make the Float64Array
available to the Rust code?