File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common.js' ) ;
4
+
5
+ /* there should be no significant performance differences
6
+ * between the hideStackFrames version and the direct
7
+ * call version
8
+ */
9
+ const bench = common . createBenchmark ( main , {
10
+ type : [ 'hide-stackframes-throw' , 'direct-call-throw' ,
11
+ 'hide-stackframes-noerr' , 'direct-call-noerr' ] ,
12
+ n : [ 10e4 ]
13
+ } , {
14
+ flags : [ '--expose-internals' ]
15
+ } ) ;
16
+
17
+ function main ( { n, type } ) {
18
+ const {
19
+ hideStackFrames,
20
+ codes : {
21
+ ERR_INVALID_ARG_TYPE ,
22
+ } ,
23
+ } = require ( 'internal/errors' ) ;
24
+
25
+ const testfn = ( value ) => {
26
+ if ( typeof value !== 'number' ) {
27
+ throw new ERR_INVALID_ARG_TYPE ( 'Benchmark' , 'number' , value ) ;
28
+ }
29
+ } ;
30
+
31
+ let fn = testfn ;
32
+ if ( type . startsWith ( 'hide-stackframe' ) )
33
+ fn = hideStackFrames ( testfn ) ;
34
+ let value = 42 ;
35
+ if ( type . endsWith ( '-throw' ) )
36
+ value = 'err' ;
37
+
38
+ bench . start ( ) ;
39
+
40
+ for ( let i = 0 ; i < n ; i ++ ) {
41
+ try {
42
+ fn ( value ) ;
43
+ // eslint-disable-next-line no-unused-vars
44
+ } catch ( e ) {
45
+ // No-op
46
+ }
47
+ }
48
+
49
+ bench . end ( n ) ;
50
+ }
You can’t perform that action at this time.
0 commit comments