I wrote the bubble sort algorithm in JavaScript and Wasm using Rust and the JS code is faster than Rust code. How is this possible?
JavaScript code
import * as wasm from "wasm-comparision-sort-algorithms";
function main() {
const arr = generateRandomArray({size: 50000, min: 1, max: 1000})
const arr2 = [...arr]
console.time("Bubble Sort JS")
bubbleSort(arr)
console.timeEnd("Bubble Sort JS")
wasm.handle_bubble_sort(arr2)
}
/**
* Algorithm to sort an array of numbers using the bubble sort algorithm.
* @param {Number[]} arr - The array of …Run Code Online (Sandbox Code Playgroud)