Fibonacci benchmarks between js, wasm and server


Date: 2023-11-15

Introduction

WebAssembly can't directly access the DOM, it has to call javascript and is known to incur a cost when doing so. What about raw computation, how does wasm compare to server-side computation or client-side javascript computation? And when is it favorable to use it?

The source code for the benchmark can be found here, along with instructions on how to build it.

Results

With an input value of 1:

With an input value of 45:

The results should appear in the browser's dev console.

This was run on a windows machine running wsl2 x86_64 GNU/Linux. Specs:

Rust version: 1.71 stable. Google chrome: Version 119.0.6045.107 (Official Build) (64-bit)

wasm-opt -O3 didn't improve performance by much. It did reduce the generated wasm size by 30 percent however.

Conclusion