@@ -59,10 +59,21 @@ const { createRunner } = require('node:bench');
5959 b . done ( ) ;
6060 } ) ) ;
6161
62+ const variableSamples = [
63+ { __proto__ : null , duration_ns : 1_000_000_000n , operations : 1 } ,
64+ { __proto__ : null , duration_ns : 100_000_000n , operations : 100 } ,
65+ ] ;
66+ const variableCompletion = runner . bench ( 'variable batch' , {
67+ samples : variableSamples . length ,
68+ } , common . mustCall ( ( b ) => {
69+ b . record ( variableSamples [ b . index ] ) ;
70+ } , variableSamples . length ) ) ;
71+
6272 const records = await runner . run ( ) . toArray ( ) ;
63- const [ controlled , recorded ] = await Promise . all ( [
73+ const [ controlled , recorded , variable ] = await Promise . all ( [
6474 controlledCompletion ,
6575 recordedCompletion ,
76+ variableCompletion ,
6677 ] ) ;
6778
6879 assert . deepStrictEqual ( invocations , [
@@ -80,8 +91,12 @@ const { createRunner } = require('node:bench');
8091 assert . strictEqual ( recorded . samples . length , 1 ) ;
8192 assert . deepStrictEqual ( recorded . samples [ 0 ] . detail ,
8293 { source : 'worker' , value : 1n } ) ;
94+ assert . deepStrictEqual ( variable . samples . map ( ( { rate } ) => rate ) , [ 1 , 1000 ] ) ;
95+ assert . strictEqual ( variable . summary . mean , 500.5 ) ;
96+ const pooledRate = 1_000_000_000 * 101 / 1_100_000_000 ;
97+ assert . notStrictEqual ( variable . summary . mean , pooledRate ) ;
8398 assert . strictEqual (
84- records . filter ( ( { type } ) => type === 'bench:sample' ) . length , 3 ) ;
99+ records . filter ( ( { type } ) => type === 'bench:sample' ) . length , 5 ) ;
85100 assert . throws ( ( ) => closedContext . start ( ) , { code : 'ERR_INVALID_STATE' } ) ;
86101 assert . throws ( ( ) => closedContext . end ( 1 ) , { code : 'ERR_INVALID_STATE' } ) ;
87102 assert . throws ( ( ) => closedContext . record ( {
0 commit comments