@@ -4,16 +4,32 @@ import { sleepSync } from '../common/index.mjs';
44import assert from 'assert' ;
55import { createHistogram , timerify } from 'perf_hooks' ;
66
7- const histogram = createHistogram ( ) ;
7+ {
8+ const histogram = createHistogram ( ) ;
89
9- const m = ( ) => {
10- // Deterministic blocking delay (~1 millisecond). The histogram operates on
11- // nanosecond precision, so this should be sufficient to prevent zero timings.
12- sleepSync ( 1 ) ;
13- } ;
14- const n = timerify ( m , { histogram } ) ;
15- assert . strictEqual ( histogram . max , 0 ) ;
16- for ( let i = 0 ; i < 10 ; i ++ ) {
17- n ( ) ;
10+ const m = ( ) => {
11+ // Deterministic blocking delay (~1 millisecond). The histogram operates on
12+ // nanosecond precision, so this should be sufficient to prevent zero timings.
13+ sleepSync ( 1 ) ;
14+ } ;
15+ const n = timerify ( m , { histogram } ) ;
16+ assert . strictEqual ( histogram . max , 0 ) ;
17+ for ( let i = 0 ; i < 10 ; i ++ ) {
18+ n ( ) ;
19+ }
20+ assert . notStrictEqual ( histogram . max , 0 ) ;
21+ }
22+
23+ // Regression test for https://github.com/nodejs/node/issues/54803
24+ // Sub-nanosecond functions must not throw ERR_OUT_OF_RANGE.
25+ {
26+ const histogram = createHistogram ( ) ;
27+ const m = ( ) => { } ;
28+ const n = timerify ( m , { histogram } ) ;
29+ for ( let j = 0 ; j < 100 ; j ++ ) {
30+ for ( let i = 0 ; i < 1000 ; i ++ ) {
31+ n ( ) ;
32+ }
33+ }
34+ assert . ok ( histogram . min >= 1 ) ;
1835}
19- assert . notStrictEqual ( histogram . max , 0 ) ;
0 commit comments