VOOZH about

URL: https://thenewstack.io/webassembly-vs-javascript-testing-side-by-side-performance/

⇱ WebAssembly vs. JavaScript: Testing Side-by-Side Performance - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2026-01-20 09:00:19
WebAssembly vs. JavaScript: Testing Side-by-Side Performance
tutorial,
JavaScript / Rust / WebAssembly

WebAssembly vs. JavaScript: Testing Side-by-Side Performance

How much faster is WebAssembly than JavaScript for heavy data processing? We do a side-by-side test using an image processor built with Rust.
Jan 20th, 2026 9:00am by Jessica Wachtel
👁 Featued image for: WebAssembly vs. JavaScript: Testing Side-by-Side Performance
Image via Unsplash+.

When we talk about WebAssembly (Wasm), we often describe it as “near-native speed” and “faster than JavaScript.” But what does that actually look like in practice?

Before we get into where Wasm excels, let’s level-set: JavaScript is still a developer’s best friend when it comes to UI. It was built to manipulate the DOM (the web’s Document Object Model) and handle CSS updates, and it does that job successfully. But we’re watching the demands of the browser change in real time. JavaScript was created in 1995 to add simple interactivity to text pages. Today, we’re asking browsers to process 4K video and run complex math that Brendan Eich (JavaScript’s creator) never envisioned.

I’ve already written a basic tutorial on how Wasm can boost your JavaScript app’s performance. Following on from that, now I will do some speed comparisons between Wasm and JavaScript.

Introduction to the Wasm vs. JS Tutorial

When you move past UI logic and into heavy data processing, JavaScript needs a partner. That’s where WebAssembly comes in. But how much faster is Wasm than JavaScript in a real-world scenario? Let’s find out.

For this project, we’re building a browser-based image processor designed to handle two distinct types of operations:

  • A “light” task: Converting a color image to grayscale.
  • A “heavy” task: Applying a sharpen filter using a computationally expensive convolution matrix.

Both operations rely heavily on mathematical conversions to change the images visually. By testing these two extremes, we can compare performance on a light task versus a heavy task.

Before getting started, make sure you have the following installed:

  • Node (used with npx to run the server): download here
  • Rust: download here
  • Wasm-pack (the WebAssembly build tool): run cargo install wasm-pack in your terminal
  • An IDE with the Rust Analyzer extension (e.g., VS Code)

Building the Image Processor With Wasm and JavaScript

This project uses Rust, because it has the most mature WebAssembly ecosystem among compiled languages. Tools like wasm-pack and wasm-bindgen generate the JavaScript glue code and handle memory translation between Rust and JavaScript, allowing you to focus on application logic.

From your main project folder, start the build process.

Create the project:

Open the working folder:

After running these commands, you’ll see the two key files:

  • Cargo.toml: Defines dependencies for the Rust project.
  • src/lib.rs: Contains the application logic. WebAssembly projects use lib.rs because they compile to a library rather than a standalone executable.

Cargo.toml is the Rust project manifest (similar to package.json). Replace the default contents with the following:

src/lib.rs contains the core image-processing logic.

The Light Task iterates through pixel data, averages the red, green and blue values, and replaces them with a single grayscale value.

The Heavy Task uses a convolution algorithm to calculate new pixel values based on neighboring pixels and applies a sharpen matrix using nested loops.

The line use wasm_bindgen::prelude::*; imports macros that allow Rust code to interface with JavaScript.

Compiling Rust Code into WebAssembly

Run the following command to compile the Rust code into WebAssembly and generate the /pkg directory:

Setting Up the HTML Frontend

index.html acts as the frontend dashboard for the performance comparison.

Users can upload an image and view results across four canvases. The page runs identical operations using WebAssembly and native JavaScript, for side-by-side timing comparisons.

The performance.now() API provides high-precision timing in milliseconds.
Note: Place index.html in the same directory as Cargo.toml.

How to Run the Performance Test

In the project directory, run npx serve and open http://localhost:3000 in your browser.

More complex operations show larger performance gaps between Wasm and JavaScript.

For meaningful results, use a 4K image (approximately 3840 × 2160 pixels).

Upload the image using the “Choose File” button and run the tests.

Performance Comparison Results

👁 Image

Across multiple runs, Wasm consistently outperformed JavaScript — about twice as fast for the light task and more than six times faster for the heavy task.

This test covers a single image on one machine. At scale, or with more complex workloads like video processing, the performance gains become even more pronounced.

TRENDING STORIES
Jessica Wachtel is a developer marketing writer at InfluxData where she creates content that helps make the world of time series data more understandable and accessible. Jessica has a background in software development and technical journalism.
Read more from Jessica Wachtel
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.