Topics In Demand
Notification
New

No notification found.

One function, many languages: A WebAssembly experiment
One function, many languages: A WebAssembly experiment

June 30, 2025

10

0

A few weeks ago, our team got curious about WebAssembly (WASM) and its promise of running code at near-native speeds in the browser. We set out to test how each WASM language performs for the same mathematical function when compiled to WebAssembly code. This WASM browser experiment led us to build a small web app to compare WASM performance across Rust, Go, C, and Python, giving us hands-on insights into WebAssembly’s potential.

What is WebAssembly?

WebAssembly is a binary format that lets WebAssembly code written in various WASM languages run efficiently in a WebAssembly browser. It compiles to near-machine code for fast execution, outpacing JavaScript in compute-heavy tasks. Its sandboxed WASM runtime keeps things secure, and its portability means code can work across platforms.

We wanted to see how WebAssembly handled a specific math function and whether WASM compilation varied by language.

The WASM experiment: Same function, different languages 

For our WASM browser experiment, we built a web app to compute nⁿ (n raised to the power of n) across a range of numbers, like 50 to 20,000. This math-intensive function was perfect for testing WASM performance. Users could pick a range, select a WASM language (Rust, Go, C, or Python), and see how long the WebAssembly code took to run. Our goal with this perfect CPU-heavy task was to compare how each language performed after WASM compilation.

Problem statement 

We had two questions:

  1. Can WebAssembly compute nⁿ efficiently enough for a responsive WebAssembly browser experience?
  2. Does the choice of WASM languages affect WASM performance in this WebAssembly performance comparison?

We built a small web app where you:

  • Select a range of numbers (e.g., 50 to 20000) 
  • Choose a language – Rust, Go, C, or Python 
  • Compute nⁿ for each number in that range 
  • See the execution time for each version 

Why WebAssembly?

WebAssembly makes it possible to run compiled languages in the browser. This means: 

  • Developers can reuse system-level code on the web.
  • Apps can gain performance boosts where JavaScript might struggle.
  • Developers aren’t locked into one language—they can choose the best tool for the job.

But does compiling to WASM level the playing field, or do some languages still outperform others? 

Languages we tested 

We coded the power(base, exponent) function in four WASM languages, each with distinct strengths:

  • Rust – Fast, safe, and ideal for systems programming
  • Go – Simple and efficient, with TinyGo for WASM
  • – The OG speedster, compiled with Emscripten
  • Python – via Pyodide, bringing the popular scripting language to the browser

How it works under the hood

Each language implements the same power() function. We compile each to .wasm using its ecosystem tools. Then the frontend loads and runs them on user input. 

Here’s a breakdown of the workflow:

1. Define the power function 

Rust: 
C:

Go:
Python (Pyodide):


2. Compile to .wasm



3. Load and run in browser 
JavaScript handles runtime loading and calculates execution time for each language: 




 

The results (Try it yourself!)

The beauty of this project is you can run the test yourself in your browser. Every language has strengths, and performance may vary based on:

  • How the WASM module was compiled
  • Overhead from bridging between JavaScript ↔ WASM
  • The language's own runtime or memory model



 


That the contents of third-party articles/blogs published here on the website, and the interpretation of all information in the article/blogs such as data, maps, numbers, opinions etc. displayed in the article/blogs and views or the opinions expressed within the content are solely of the author's; and do not reflect the opinions and beliefs of NASSCOM or its affiliates in any manner. NASSCOM does not take any liability w.r.t. content in any manner and will not be liable in any manner whatsoever for any kind of liability arising out of any act, error or omission. The contents of third-party article/blogs published, are provided solely as convenience; and the presence of these articles/blogs should not, under any circumstances, be considered as an endorsement of the contents by NASSCOM in any manner; and if you chose to access these articles/blogs , you do so at your own risk.


© Copyright nasscom. All Rights Reserved.