Skip to content

Add a page of microbenchmarks for wasm-bindgen #1512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ wasm-bindgen-test-crate-b = { path = 'tests/crates/b', version = '0.1' }

[workspace]
members = [
"benchmarks",
"crates/cli",
"crates/js-sys",
"crates/macro/ui-tests",
Expand Down
27 changes: 20 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,9 @@ jobs:
steps:
- template: ci/azure-install-rust.yml
- template: ci/azure-install-sccache.yml
- template: ci/azure-install-wasm-pack.yml
- script: mv _package.json package.json && npm install && rm package.json
displayName: "run npm install"
- script: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
displayName: "install wasm-pack"
- script: |
set -ex
cargo build -p wasm-bindgen-cli
ln -snf `pwd`/target/debug/wasm-bindgen $HOME/.cargo/bin/wasm-bindgen
displayName: "install wasm-bindgen for `wasm-pack` to use"
- script: |
for dir in `ls examples | grep -v README | grep -v asm.js | grep -v raytrace | grep -v without-a-bundler`; do
(cd examples/$dir &&
Expand Down Expand Up @@ -190,6 +184,19 @@ jobs:
artifactName: examples2
targetPath: '$(Build.ArtifactStagingDirectory)'

- job: build_benchmarks
displayName: "Build benchmarks"
steps:
- template: ci/azure-install-rust.yml
- template: ci/azure-install-sccache.yml
- template: ci/azure-install-wasm-pack.yml
- script: wasm-pack build --target web benchmarks
displayName: "build benchmarks"
- task: PublishPipelineArtifact@0
inputs:
artifactName: benchmarks
targetPath: benchmarks

- job: dist_linux
displayName: "Dist Linux binary"
steps:
Expand Down Expand Up @@ -292,6 +299,7 @@ jobs:
- dist_windows
- build_examples
- build_raytrace
- build_benchmarks
displayName: "Deploy everything"
steps:
- template: ci/azure-install-rust.yml
Expand All @@ -315,6 +323,11 @@ jobs:
inputs:
artifactName: examples2
targetPath: gh-pages/exbuild/raytrace-parallel
- task: DownloadPipelineArtifact@0
displayName: "Download benchmarks"
inputs:
artifactName: benchmarks
targetPath: gh-pages/benchmarks
- task: DownloadPipelineArtifact@0
displayName: "Download dist - windows"
inputs:
Expand Down
11 changes: 11 additions & 0 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "wasm-bindgen-benchmark"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]

[dependencies]
wasm-bindgen = "0.2.43"
web-sys = { version = "0.3.20", features = ['Node'] }

[lib]
crate-type = ['cdylib']
54 changes: 54 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Microbenchmarks for `wasm-bindgen`

This folder houses a number of microbenchmarks for `wasm-bindgen`. These, like
all microbenchmarks, should be taken with a grain of salt. They are intended to
help developers understand changes over time, but they are not intended to be a
performance suite for WebAssembly for Rust.

[View benchmarks for `master` branch online][online]

[online]: https://rustwasm.github.io/wasm-bindgen/benchmarks/

## Building and Running

First, copy the benchmarks to a temporary directory:

```
$ cp ./benchmarks /some/other/directory
```

Next, `cd` into that directory and execute:

```
$ wasm-pack build --target web
```

Next, use your favorite static file server to host the current directory. For
example using the [`https` crate](https://crates.io/crates/https):

```
$ http
```

Then open up a web browser and view http://localhost:8000, for example.

You should be presented a page with lots of `(run)` links, where when you click
them it will execute the benchmark and then display the result.

## Benchmark Architecture

Currently benchmarks are pretty bare bones. They just use benchmark.js to
generate statistics which are then rendered to the screen. Benchmarks are listed
one-by-one in `index.html` where a `td` exists for each benchmark. In `index.js`
each of the `td`'s `id` properties are hooked up to an actual function to
benchmark, depending on what's being benchmarked.

Relevant files are:

* `index.html` - the page showing all benchmarks
* `index.js` - the driver JS for all benchmarks
* `globals.js` - global JS functions imported by all other benchmarks
* `js-bencharks.js` - the JS functions that we're benchmarking
* `src/lib.rs` - the Rust/`wasm-bindgen` functions we're benchmarking
* `raw.wast`/`raw.wasm` - a raw handwritten WebAssembly file used in some
benchmarks. A compiled version of this is checked into the repository.
5 changes: 5 additions & 0 deletions benchmarks/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function jsthunk() {}
export function add(a, b) { return a + b; }
export class Foo {
bar() {}
}
Loading