This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wasm-pack build --target web |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [package] | |
| name = "wasm-image-proc" | |
| version = "0.1.0" | |
| edition = "2021" | |
| [lib] | |
| crate-type = ["cdylib"] | |
| [dependencies] | |
| wasm-bindgen = "0.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cd wasm-image-proc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cargo new wasm-image-proc --lib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.getElementById("summary-output").innerText = summary_text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pyodide.globals.set("csv_text", text); |
NewerOlder