JavaScript vs WebAssembly

A practical visual performance comparison of CPU-intensive image processing tasks.

About This Research

What if WebAssembly is not truly faster than JS everywhere? This project tries to understand whereS and howS.

Why Image Processing?

Why not? Image processing is a commonly used in most popular applications today and it requires a lot of CPU power, which makes it a suitable choice for optimizing with WASM.

Measured Metrics

  • Execution Time: Total processing duration in milliseconds
  • Cold start: Time taken for the first run, including any initialization overhead
  • Pixel Rate: Number of pixels processed per second (MP/s)
  • Consistency: Variability in execution time across multiple runs
  • Image Size Impact: How performance scales with different image sizes

Performance Benchmarks

Test 01

Color Inversion

Lightweight operation - inverting RGB values pixel by pixel

Test 01 Color Inversion
0 px
0 px
Original
Original uploaded image
Original
Results Verified Identical
JavaScript
3
Click "Select Image" below
Processing result
WebAssembly
3
Same image as JavaScript
Processing result
⟩ Performance Analysis
Run tests to see performance comparison
Test 02

Edge detection

Medium-intensity operation - detecting edges using the Sobel operator

Test 02 Edge detection
0 px
0 px
Original
Original uploaded image
Original
Results Verified Identical
JavaScript
3
Click "Select Image" below
Processing result
WebAssembly
3
Same content as JavaScript
Processing result
⟩ Performance Analysis
Run tests to see performance comparison
Test 03

Color Quantization (K-Means)

High-weight operation - reducing colors using K-Means clustering algorithm

Test 03 Color Quantization (K-Means)
0 px
0 px
Original
Original uploaded image
Original
Results Verified Identical
JavaScript
3
Click "Select Image" below
Processing result
WebAssembly
3
Same image as JavaScript
Processing result
(2-256 colors)
⟩ Performance Analysis
Run tests to see performance comparison

Methodology

Each test runs multiple iterations (1-30 depending on image size) to ensure statistical reliability. Results show the median value to reduce the impact of outliers caused by browser garbage collection or system processes. Run counts and other variables related to the tests are

fully customizable
in the settings panel, but initially predefined in order to fit my computer's capabilities. (Sorry)

Test Settings

pixels
MP
MP
iterations
iterations
iterations