boopathi / mst

Visualize minimum spanning tree

Home Page:https://mst.boopathi.in/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mst

A demo of Kruskal's algorithm for Minimum Spanning Tree in JS and Rust(wasm).

https://mst.boopathi.in/

The graph

  • Nodes: Generate n random points in the full screen canvas
  • Edges: Every node is connected to every other node. n * (n-1) / 2 edges
  • Weights: The weight of an edge is the distance between the two nodes it connects

Try it locally

Requirements

Build

The rust library mst needs to be built using wasm-pack with the config to output for web (this target takes care of fetching of the wasm file and the WebAssembly instantiation).

wasm-pack build --target web

Run

After the wasm files are built you can verify it by looking into the pkg/ directory, the following files -

  • pkg/mst.js
  • pkg/mst_bg.wasm

which will be fetched from main.js

Simply start a static file server to serve index.html

python -m SimpleHTTPServer

Findings

Rust performs ~3x-4x faster for bigger graphs. For smaller ones, the performance improvement is not worth the effort - numNodes=100 gives 8ms(JS) to 6ms(Rust) improvement.

[RUST] Took ~137ms to send input, construct Graph in Rust and compute MST for 1000 nodes with 499500 edges and serialize in Rust and deserialize in JS 999 edges
[JS] Took ~451ms to compute MST for 1000 nodes with 499500 edges

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Visualize minimum spanning tree

https://mst.boopathi.in/

License:Other


Languages

Language:JavaScript 60.8%Language:Rust 29.3%Language:HTML 6.3%Language:Shell 3.7%