import { useState } from 'react' import { Box, Button, Paper, Stack, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography, LinearProgress, Link, } from '@mui/material' import { getQhull } from '../qhull' import { points2D, points3D } from '../points' import benchScript from '../../scripts/qhull_benchmark.m?raw' const SIZES = [1000, 5000, 20000, 50000] interface Row { n: number; ms2: number; ms3: number; simp2: number; simp3: number } const yield_ = () => new Promise((r) => setTimeout(r, 0)) export function Benchmarks() { const [rows, setRows] = useState([]) const [running, setRunning] = useState(false) const [progress, setProgress] = useState(0) const run = async () => { setRunning(true); setRows([]); setProgress(0) const q = await getQhull() const out: Row[] = [] for (let i = 0; i < SIZES.length; i++) { const n = SIZES[i] await yield_() const p2 = points2D(n, 'uniform', 12345 + i) let t = performance.now() const r2 = q.delaunay(p2, 2) const ms2 = performance.now() - t const p3 = points3D(n, 'uniform', 54321 + i) t = performance.now() const r3 = q.delaunay(p3, 3) const ms3 = performance.now() - t out.push({ n, ms2, ms3, simp2: r2.facets.length, simp3: r3.facets.length }) setRows([...out]); setProgress(((i + 1) / SIZES.length) * 100) } setRunning(false) } const download = () => { const blob = new Blob([benchScript], { type: 'text/plain' }) const a = document.createElement('a') a.href = URL.createObjectURL(blob) a.download = 'qhull_benchmark.m' a.click() URL.revokeObjectURL(a.href) } return ( Delaunay triangulation of uniform random points, timed in your browser via qhull-wasm. Run the matching .m script below in MATLAB, Octave, or{' '} numbl for an apples-to-apples comparison (all three triangulate via Qhull). {running && } {rows.length > 0 && ( N 2D (ms) 2D simplices 3D (ms) 3D simplices {rows.map((r) => ( {r.n.toLocaleString()} {r.ms2.toFixed(1)} {r.simp2.toLocaleString()} {r.ms3.toFixed(1)} {r.simp3.toLocaleString()} ))}
)} Comparison script (MATLAB / Octave / numbl)
{benchScript}
) }