rustwasm / book

The Rust and WebAssembly Book
https://rustwasm.github.io/docs/book/
MIT License
1.75k stars 211 forks source link

Instructions to prepare `lib.rs` for benchmarking are inadequate #241

Open prestonhale opened 4 years ago

prestonhale commented 4 years ago

Where in the docs did you come across this? Time Profiling Chapter: We also have to comment out all the #[wasm_bindgen] annotations, and the "cdylib" bits from Cargo.toml or else building native code will fail and have link errors.

Describe what about it does not make sense These instructions were inadequate for me to the run the benchmark. I got errors as below:

panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets', /Users/username/.cargo/registry/src/github.com-1/web-sys-0.3.45/src/features/gen_console.rs:5:5

These were resolved by commenting out js_sys and web_sys imports. js_sys is an optional import from "extra credit" in a previous chapter. web_sys is for the Timer struct designed earlier in this chapter. I also had to revert to the book's initial modulo based solution for random cells rather than Math::random() since js_sys was removed.

Why does it not make sense? Users closely following the book will receive somewhat cryptic errors.

How could we improve it? Mention other imports that will need to be removed in order run the benchmarks. I'd also be curious to hear ideas for benchmarking that don't rely on removing wasm code entirely. As the code base grows, removing web_sys could be a major pain.