Last active
November 5, 2021 19:38
-
-
Save DanielRamosAcosta/e36646e5d0c38df07fdf224644eac668 to your computer and use it in GitHub Desktop.
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
| import { BenchmarkRunResult } from "https://deno.land/std/testing/bench.ts"; | |
| function typicalDeviation(data: number[]) { | |
| const avg = data.reduce((a, b) => a + b) / data.length; | |
| const squareDiffs = data.map((value) => { | |
| const diff = value - avg; | |
| const sqrDiff = diff * diff; | |
| return sqrDiff; | |
| }); | |
| const avgSquareDiff = squareDiffs.reduce((a, b) => a + b) / data.length; | |
| const stdDev = Math.sqrt(avgSquareDiff); | |
| return stdDev; | |
| } | |
| export function denoBenchToBenchmarkJsOutput(result: BenchmarkRunResult) { | |
| return result.results.map((r) => ({ | |
| opsPerSec: Math.round(1000 / r.measuredRunsAvgMs), | |
| error: Math.round(typicalDeviation(r.measuredRunsMs) * 100) / 100, | |
| name: r.name, | |
| runs: r.runsCount, | |
| })).map((r) => | |
| `${r.name} x ${r.opsPerSec} ops/sec ±${r.error}% (${r.runs} runs sampled)` | |
| ).join("\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment