11const { platform, arch, availableParallelism, totalmem } = require ( "node:os" ) ;
22const fs = require ( "node:fs" ) ;
33const path = require ( "node:path" ) ;
4+ const { summarize } = require ( "../utils/analyze" ) ;
45
56const formatter = Intl . NumberFormat ( undefined , {
67 notation : "standard" ,
@@ -12,22 +13,6 @@ const timer = Intl.NumberFormat(undefined, {
1213 maximumFractionDigits : 3 ,
1314} ) ;
1415
15- const formatTime = ( time ) => {
16- if ( time < 0.000001 ) {
17- // Less than 1 microsecond, show in nanoseconds
18- return `${ ( time * 1000000000 ) . toFixed ( 2 ) } ns` ;
19- } else if ( time < 0.001 ) {
20- // Less than 1 millisecond, show in microseconds
21- return `${ ( time * 1000000 ) . toFixed ( 2 ) } µs` ;
22- } else if ( time < 1 ) {
23- // Less than 1 second, show in milliseconds
24- return `${ ( time * 1000 ) . toFixed ( 2 ) } ms` ;
25- } else {
26- // 1 second or more, show in seconds
27- return `${ time . toFixed ( 2 ) } s` ;
28- }
29- } ;
30-
3116const valueToDuration = ( maxValue , value , isTimeBased , scalingFactor = 10 ) => {
3217 const normalizedValue = isTimeBased ? maxValue / value : value / maxValue ;
3318 const baseSpeed = ( 1 / normalizedValue ) * scalingFactor ;
@@ -92,30 +77,31 @@ const templatePath = path.join(__dirname, "template.html");
9277const template = fs . readFileSync ( templatePath , "utf8" ) ;
9378
9479function htmlReport ( results ) {
80+ const summary = summarize ( results ) ;
9581 const primaryMetric =
9682 results [ 0 ] ?. opsSec !== undefined ? "opsSec" : "totalTime" ;
9783 let durations ;
9884
9985 if ( primaryMetric === "opsSec" ) {
100- const maxOpsSec = Math . max ( ...results . map ( ( b ) => b . opsSec ) ) ;
101- durations = results . map ( ( r ) => ( {
86+ const maxOpsSec = Math . max ( ...summary . map ( ( b ) => b . opsSec ) ) ;
87+ durations = summary . map ( ( r ) => ( {
10288 name : r . name . replaceAll ( " " , "-" ) ,
10389 duration : valueToDuration ( maxOpsSec , r . opsSec , false ) ,
10490 metricValueFormatted : formatter . format ( r . opsSec ) ,
10591 metricUnit : "ops/sec" ,
106- minFormatted : timer . format ( r . histogram . min ) , // Use timer for ns format
107- maxFormatted : timer . format ( r . histogram . max ) ,
92+ minFormatted : timer . format ( r . min ) , // Use timer for ns format
93+ maxFormatted : timer . format ( r . max ) ,
10894 } ) ) ;
10995 } else {
11096 // metric === 'totalTime'
111- const maxTotalTime = Math . max ( ...results . map ( ( b ) => b . totalTime ) ) ;
112- durations = results . map ( ( r ) => ( {
97+ const maxTotalTime = Math . max ( ...summary . map ( ( b ) => b . totalTime ) ) ;
98+ durations = summary . map ( ( r ) => ( {
11399 name : r . name . replaceAll ( " " , "-" ) ,
114100 duration : valueToDuration ( maxTotalTime , r . totalTime , true ) ,
115- metricValueFormatted : formatTime ( r . totalTime ) ,
101+ metricValueFormatted : r . totalTimeFormatted ,
116102 metricUnit : "total time" ,
117- minFormatted : timer . format ( r . histogram . min ) , // Use timer for ns format
118- maxFormatted : timer . format ( r . histogram . max ) ,
103+ minFormatted : timer . format ( r . min ) , // Use timer for ns format
104+ maxFormatted : timer . format ( r . max ) ,
119105 } ) ) ;
120106 }
121107
0 commit comments