|
| 1 | +## VM benchmark tests |
| 2 | + |
| 3 | +This microbenchmark consists of a few tests which can be used to measure performance of various WebAssembly virtual machines. It should be noted this benchmark is by definition is not comprehensive and might not reflect performance on real life workloads. |
| 4 | + |
| 5 | +However, each test was crafted in a way that would prevent the virtual machine from optimizing them using the dead code elimination. Most tests also prevent intermediate results memoization (with `fibonacci_bigint` and `factorization_reikna` being exceptions) and allow to specify an RNG seed to obtain repeatable benchmark results. |
| 6 | + |
| 7 | +Each test exports the `main` function which is called by the benchmark runner. There are also few compile-time parameters in each test that can be adjusted using the corresponding environment variables. The benchmark has been successfully tested on Mac and should run smoothly on Linux as well. |
| 8 | + |
| 9 | +To run tests Rust Cargo package manager should be installed – the easiest way would be to follow these instructions: |
| 10 | + |
| 11 | +```shell |
| 12 | +# download and install rustup |
| 13 | +curl -sSf https://static.rust-lang.org/rustup.sh | sh |
| 14 | + |
| 15 | +# install the latest nightly toolchain |
| 16 | +~/.cargo/bin/rustup toolchain install nightly |
| 17 | + |
| 18 | +# make shure that Rust is up to date |
| 19 | +rustup update |
| 20 | + |
| 21 | +# install the Webassembly target for Rust |
| 22 | +rustup target add wasm32-unknown-unknown --toolchain nightly |
| 23 | +``` |
| 24 | +Below we also assume that Fluence GitHub repo has been already cloned and we are in the `vm_bench/tests` directory: |
| 25 | + |
| 26 | +```shell |
| 27 | +git clone --recursive https://github.com/fluencelabs/fluence |
| 28 | +cd fluence/vm/vm_bench/tests |
| 29 | +``` |
| 30 | + |
| 31 | +Random numbers in tests are generated with [IsaacRng](https://doc.rust-lang.org/1.0.0/rand/isaac/struct.IsaacRng.html). It should also be noted relative results of the QR and SVG decomposition tests can be somewhat different on different hardware because of the floating point non-determinism. |
| 32 | + |
| 33 | +### Compression |
| 34 | + |
| 35 | +This test compresses a sequence of `SEQUENCE_SIZE` bytes and has `ITERATIONS_COUNT` iterations of compressions. On each iteration a new sequence is generated by the seed that was computed based on the previous sequence. As the first seed the `SEED` parameter is used. Two compression algorithms ([deflate](https://docs.rs/deflate) and [snappy](https://docs.rs/snap)) are supported and can be chosen by specifying the `deflate_compression` flag. |
| 36 | + |
| 37 | +To run: |
| 38 | + |
| 39 | +```shell |
| 40 | +cd recursive_hash |
| 41 | +ITERATIONS_COUNT=1 SEED=1000000 SEQUENCE_SIZE=1024 cargo build --release --target wasm32-unknown-unknown [--feature "deflate_compression"] |
| 42 | +``` |
| 43 | + |
| 44 | +### Factorization |
| 45 | + |
| 46 | +This test factorizes provided `FACTORIZED_NUMBER` using [reikna](https://docs.rs/reikna/0.10.0/reikna/) library. |
| 47 | + |
| 48 | +To run: |
| 49 | + |
| 50 | +```shell |
| 51 | +cd factorization_reikna |
| 52 | +FACTORIZED_NUMBER=2147483647 cargo build --release --target wasm32-unknown-unknown |
| 53 | +``` |
| 54 | + |
| 55 | +### Recursive fibonacci computing |
| 56 | + |
| 57 | +This test recursively computes the Fibonacci number with the index `FIB_NUMBER`. |
| 58 | + |
| 59 | +To run: |
| 60 | + |
| 61 | +```shell |
| 62 | +cd fibonacci_bigint |
| 63 | +FIB_NUMBER=38 cargo build --release --target wasm32-unknown-unknown |
| 64 | +``` |
| 65 | + |
| 66 | +### Matrix product |
| 67 | + |
| 68 | +This test computes a product of random generated matrices of size `MATRIX_SIZE`. There are `ITERATIONS_COUNT` iterations; on each iteration new matrices are generated using the seed that was computed using the previous product result. As the first seed the `SEED` parameter is used. |
| 69 | + |
| 70 | +To run: |
| 71 | + |
| 72 | +```shell |
| 73 | +cd matrix_product |
| 74 | +ITERATIONS_COUNT=1000000 SEED=1 MATRIX_SIZE=10 cargo build --release --target wasm32-unknown-unknown |
| 75 | +``` |
| 76 | + |
| 77 | +### Matrix QR decomposition |
| 78 | + |
| 79 | +This test computes a QR decomposition of random generated matrices of size `MATRIX_SIZE`. There are `ITERATIONS_COUNT` iterations of decomposition; on each iteration a new matrix is generated using the seed that was computed using the previous decomposition result. As the first seed the `SEED` parameter is used. |
| 80 | + |
| 81 | +To run: |
| 82 | + |
| 83 | +```shell |
| 84 | +cd matrix_qr_decomposition |
| 85 | +ITERATIONS_COUNT=1000000 SEED=1 MATRIX_SIZE=10 cargo build --release --target wasm32-unknown-unknown |
| 86 | +``` |
| 87 | + |
| 88 | +### Matrix SVD decomposition |
| 89 | + |
| 90 | +This test computes an SVD decomposition of random generated matrices of size `MATRIX_SIZE`. There are `ITERATIONS_COUNT` iterations of decomposition; on each iteration a new matrix is generated using the seed that was computed using the previous decomposition result. As the first seed the `SEED` parameter is used. |
| 91 | + |
| 92 | +To run: |
| 93 | + |
| 94 | +```shell |
| 95 | +cd matrix_svd_decomposition |
| 96 | +ITERATIONS_COUNT=1000000 SEED=1 MATRIX_SIZE=10 cargo build --release --target wasm32-unknown-unknown |
| 97 | +``` |
| 98 | + |
| 99 | +### Recursive hash computing |
| 100 | + |
| 101 | +This test iteratively computes a hash chain `hash(hash( ... hash(x)))` of length `ITERATIONS_COUNT`, where `x` is the initial value specified by `INITIAL_VALUE`. |
| 102 | + |
| 103 | +To run: |
| 104 | + |
| 105 | +```shell |
| 106 | +cd recursive_hash |
| 107 | +ITERATIONS_COUNT=10000000 INITIAL_VALUE=0 cargo build --release --target wasm32-unknown-unknown |
| 108 | +``` |
0 commit comments