小编Ela*_*cha的帖子

Why is bubble sort faster when implemented in JavaScript then when implemented in Wasm using Rust?

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)

javascript algorithm bubble-sort rust rust-wasm

7
推荐指数
0
解决办法
410
查看次数

标签 统计

algorithm ×1

bubble-sort ×1

javascript ×1

rust ×1

rust-wasm ×1