Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wasm vs JS: The Showdown</title>
<style>
body { font-family: sans-serif; text-align: center; background: #f4f4f4; padding: 20px; }
.race-box { background: white; padding: 20px; border-radius: 10px; margin: 20px auto; max-width: 800px; border: 1px solid #ddd; }
.container { display: flex; justify-content: center; gap: 20px; }
canvas { background: #eee; max-width: 45%; height: auto; border: 1px solid #999; }
wasm-pack build --target web
use wasm_bindgen::prelude::*;
// RACE 1: Light Task (Grayscale conversion)
#[wasm_bindgen]
pub fn apply_grayscale_wasm(pixels: &mut [u8]) {
for i in (0..pixels.len()).step_by(4) {
let r = pixels[i] as u32;
let g = pixels[i + 1] as u32;
let b = pixels[i + 2] as u32;
let avg = ((r + g + b) / 3) as u8;
[package]
name = "wasm-image-proc"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2"
cargo new wasm-image-proc --lib
document.getElementById("summary-output").innerText = summary_text
pyodide.runPython(`
import pandas as pd
from io import StringIO
from js import document
# Load CSV
df = pd.read_csv(StringIO(csv_text))
# Show first rows
document.getElementById("data-output").innerText = df.head().to_string()
pyodide.runPython(`
import pandas as pd
from io import StringIO
from js import document
# Load CSV
df = pd.read_csv(StringIO(csv_text))
# Show first rows
document.getElementById("data-output").innerText = df.head().to_string()
pyodide.globals.set("csv_text", text);