@@ -9,18 +9,10 @@ const { analyze } = require("../utils/analyze.js");
99 * @param {number } total - The maximum value in the dataset (for scaling)
1010 * @param {number } samples - Number of samples collected
1111 * @param {string } metric - The metric being displayed (opsSec or totalTime)
12+ * @param {number } width - Length of the bar in characters
1213 * @param {string } [comment=""] - optional additional comment
13- * @param {number } [length=25] - Length of the bar in characters
1414 */
15- function drawBar (
16- label ,
17- value ,
18- total ,
19- samples ,
20- metric ,
21- comment = "" ,
22- length = 25 ,
23- ) {
15+ function drawBar ( label , value , total , samples , metric , width , comment = "" ) {
2416 let percentage ;
2517 let displayedValue ;
2618 let displayedMetric ;
@@ -52,15 +44,15 @@ function drawBar(
5244 displayedMetric = "total time" ;
5345 }
5446
55- const ratio = length * percentage ;
47+ const ratio = width * percentage ;
5648 const filledLength = Math . floor ( ratio ) ;
5749 const fraction = ratio % 1 ;
5850 const partial = fraction >= 0.5 ? "▌" : "" ;
5951
6052 const bar =
6153 "█" . repeat ( filledLength ) +
6254 partial +
63- "─" . repeat ( length - filledLength - partial . length ) ;
55+ "─" . repeat ( width - filledLength - partial . length ) ;
6456
6557 const displayedSamples = `${ styleText ( [ "yellow" ] , samples . toString ( ) . padStart ( 2 ) ) } samples` ;
6658
@@ -99,7 +91,10 @@ function chartReport(results, options = { labelWidth: 45, printHeader: true }) {
9991 * @param {BenchmarkResult[] } results - Array of benchmark results
10092 * @param options {object} layout options
10193 */
102- function toChart ( results , options = { labelWidth : 45 , printHeader : true } ) {
94+ function toChart (
95+ results ,
96+ options = { labelWidth : 45 , printHeader : true , barWidth : 25 } ,
97+ ) {
10398 // Determine the primary metric and calculate max value for scaling
10499 const primaryMetric =
105100 results [ 0 ] ?. opsSec !== undefined ? "opsSec" : "totalTime" ;
@@ -151,6 +146,7 @@ function toChart(results, options = { labelWidth: 45, printHeader: true }) {
151146 maxValue ,
152147 result . histogram . samples ,
153148 primaryMetric ,
149+ options . barWidth ?? 25 ,
154150 comment ,
155151 ) ;
156152 }
0 commit comments