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] // Reference timings from running scripts/qhull_benchmark.m on a Linux laptop. // Hardware-dependent — for rough comparison only. const REFERENCE: { n: number; numbl: [number, number]; octave: [number, number]; matlab: [number, number] }[] = [ { n: 1000, numbl: [4.1, 16.5], octave: [4.5, 10.1], matlab: [21.1, 21.3] }, { n: 5000, numbl: [18.6, 54.3], octave: [12.2, 61.3], matlab: [28.6, 185.5] }, { n: 20000, numbl: [65.5, 287.3], octave: [55.6, 336.3], matlab: [179.9, 624.2] }, { n: 50000, numbl: [154.7, 757.0], octave: [174.9, 973.9], matlab: [373.8, 1703.9] }, ] 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}
Run it with matlab -batch qhull_benchmark, octave qhull_benchmark.m, or numbl run qhull_benchmark.m. Reference desktop timings (Delaunay, ms) Measured on one Linux laptop — hardware-dependent, for rough comparison only. N numbl 2D numbl 3D Octave 2D Octave 3D MATLAB 2D MATLAB 3D {REFERENCE.map((r) => ( {r.n.toLocaleString()} {r.numbl[0].toFixed(1)} {r.numbl[1].toFixed(1)} {r.octave[0].toFixed(1)} {r.octave[1].toFixed(1)} {r.matlab[0].toFixed(1)} {r.matlab[1].toFixed(1)} ))}
) }