This project benchmarks a 1D convolution implementation comparing different execution methods:
- WebAssembly in browser
- WebAssembly in Node.js
- Native shared library from Node.js
- Native CLI executable
- CMake (for native builds)
- Emscripten (for WebAssembly builds)
- Node.js with build tools for native modules
- Python3 or any other local web server (for browser tests)
- Install Node.js dependencies:
# Install required packages for native and WASM benchmarks
npm installNote: The ffi-napi and ref-napi packages require Python and a C/C++ compiler to be installed for building native modules. On Linux, you may need to install build-essential. On macOS, you need Xcode Command Line Tools.
- Build both native and WebAssembly versions:
./build.shThis will:
- Create native builds (CLI executable and shared library) in the
builddirectory - Create WebAssembly builds (
conv.jsandconv.wasm)
Run the native executable directly:
./build/conv1d_cliThe Node.js benchmark compares the native shared library against the WebAssembly version:
# Run the benchmark
node benchmark.jsThis will:
- Load both the native shared library and WebAssembly module
- Run convolution operations with specified input/kernel sizes (default: input size 100000, kernel size 100)
- Perform 100 iterations of each operation
- Report timing comparisons between native and WASM versions
The benchmark outputs:
- WASM execution time in milliseconds
- Native execution time in milliseconds
Common issues:
- If you get errors about missing .so files, ensure
build.shcompleted successfully - If you get node-gyp errors during npm install, ensure you have Python and build tools installed
- Start a local web server. For example, using Python:
# Python 3
python3 -m http.server
# Python 2
python -m SimpleHTTPServer- Open
http://localhost:8000/benchmark.htmlin your web browser
The browser benchmark provides an interactive interface where you can:
- Adjust input size
- Adjust kernel size
- Set number of iterations
- Run benchmarks and see results in a table
conv.c- Core convolution implementationmain.c- CLI program implementationbenchmark.js- Node.js benchmark scriptbenchmark.html- Browser-based benchmarkbuild.sh- Build script for native and WASM versionsCMakeLists.txt- CMake configuration for native builds
- The browser benchmark only tests WebAssembly performance since native code cannot run in browsers
- The Node.js benchmark compares both native and WebAssembly performance
- Memory is automatically managed in all versions, but explicit cleanup is performed in WebAssembly tests
- The convolution implementation uses double precision floating point numbers