This is an experiment of calling rust methods from JavaScript.

Performance comparison of running a loop 10e7 times b/w Rust(WASM) vs. JS

Check the console and refresh to see WASM magic

// Rust code
#[no_mangle] 
pub fn add_one(limit: i32) -> i32 { 
  let mut x = 0; 
  for _n in 0..limit { 
    x = x + 2; 
  } 
  return x; 
}
  
// JS Code
function loopRunner(limit) { 
  limit = limit; 
  var x = 0; 
  for (i = 0; i < limit; i++) { 
    x = x + 2; 
  } 
  return x; 
}
    
Console :