@@ -6,53 +6,10 @@ import {
66 type BenchmarkStats ,
77} from "@codspeed/core" ;
88import { Bench , TaskResult } from "tinybench" ;
9- import { taskUriMap } from "./index " ;
9+ import { getTaskUri } from "./uri " ;
1010
1111declare const __VERSION__ : string ;
1212
13- function getTaskUri (
14- bench : Bench ,
15- taskName : string ,
16- rootCallingFile : string
17- ) : string {
18- const uriMap = taskUriMap . get ( bench ) ;
19- return uriMap ?. get ( taskName ) || `${ rootCallingFile } ::${ taskName } ` ;
20- }
21-
22- function convertTinybenchResultToBenchmarkStats (
23- result : TaskResult ,
24- warmupIterations : number
25- ) : BenchmarkStats {
26- // All tinybench times are in milliseconds, convert to nanoseconds
27- const ms_to_ns = ( ms : number ) => ms * 1_000_000 ;
28-
29- const { min, max, mean, sd, samples } = result . latency ;
30-
31- // Get individual sample times in nanoseconds and sort them
32- const sortedTimesNs = samples . map ( ms_to_ns ) . sort ( ( a , b ) => a - b ) ;
33- const meanNs = ms_to_ns ( mean ) ;
34- const stdevNs = ms_to_ns ( sd ) ;
35-
36- const { q1_ns, q3_ns, median_ns, iqr_outlier_rounds, stdev_outlier_rounds } =
37- calculateQuantiles ( { meanNs, stdevNs, sortedTimesNs } ) ;
38-
39- return {
40- min_ns : ms_to_ns ( min ) ,
41- max_ns : ms_to_ns ( max ) ,
42- mean_ns : meanNs ,
43- stdev_ns : stdevNs ,
44- q1_ns,
45- median_ns,
46- q3_ns,
47- total_time : result . totalTime / 1_000 , // convert from ms to seconds
48- iter_per_round : sortedTimesNs . length ,
49- rounds : 1 , // Tinybench only runs one round
50- iqr_outlier_rounds,
51- stdev_outlier_rounds,
52- warmup_iters : warmupIterations ,
53- } ;
54- }
55-
5613export function runWalltimeBench ( bench : Bench , rootCallingFile : string ) : void {
5714 bench . run = async ( ) => {
5815 console . log (
@@ -125,3 +82,37 @@ export function runWalltimeBench(bench: Bench, rootCallingFile: string): void {
12582 return results ;
12683 } ;
12784}
85+
86+ function convertTinybenchResultToBenchmarkStats (
87+ result : TaskResult ,
88+ warmupIterations : number
89+ ) : BenchmarkStats {
90+ // All tinybench times are in milliseconds, convert to nanoseconds
91+ const ms_to_ns = ( ms : number ) => ms * 1_000_000 ;
92+
93+ const { min, max, mean, sd, samples } = result . latency ;
94+
95+ // Get individual sample times in nanoseconds and sort them
96+ const sortedTimesNs = samples . map ( ms_to_ns ) . sort ( ( a , b ) => a - b ) ;
97+ const meanNs = ms_to_ns ( mean ) ;
98+ const stdevNs = ms_to_ns ( sd ) ;
99+
100+ const { q1_ns, q3_ns, median_ns, iqr_outlier_rounds, stdev_outlier_rounds } =
101+ calculateQuantiles ( { meanNs, stdevNs, sortedTimesNs } ) ;
102+
103+ return {
104+ min_ns : ms_to_ns ( min ) ,
105+ max_ns : ms_to_ns ( max ) ,
106+ mean_ns : meanNs ,
107+ stdev_ns : stdevNs ,
108+ q1_ns,
109+ median_ns,
110+ q3_ns,
111+ total_time : result . totalTime / 1_000 , // convert from ms to seconds
112+ iter_per_round : sortedTimesNs . length ,
113+ rounds : 1 , // Tinybench only runs one round
114+ iqr_outlier_rounds,
115+ stdev_outlier_rounds,
116+ warmup_iters : warmupIterations ,
117+ } ;
118+ }
0 commit comments