@@ -14,46 +14,72 @@ function ForEachBench() {
14
14
console . log ( "starting forEach benchmark" ) ;
15
15
const tb = new TypedFastBitSet ( ) ;
16
16
const stb = new SparseTypedFastBitSet ( ) ;
17
+ const tb_small = new TypedFastBitSet ( ) ;
17
18
18
19
const s = new Set ( ) ;
19
20
for ( let i = 0 ; i < N ; i ++ ) {
21
+ if ( i < 100 ) {
22
+ tb_small . add ( i ) ;
23
+ }
20
24
tb . add ( smallgap * i + 5 ) ;
21
25
stb . add ( smallgap * i + 5 ) ;
22
26
}
23
27
24
28
const suite = new Benchmark . Suite ( ) ;
25
29
// add tests
26
30
const ms = suite
27
- . add ( "TypedFastBitSet-forof" , function ( ) {
28
- let card = 0 ;
29
- for ( const element of stb ) {
30
- card ++ ;
31
- }
32
- return card ;
33
- } )
34
- . add ( "TypedFastBitSet-foreach" , function ( ) {
35
- let card = 0 ;
36
- const inc = function ( ) {
37
- card ++ ;
38
- } ;
39
- tb . forEach ( inc ) ;
40
- return card ;
41
- } )
42
- . add ( "SparseTypedFastBitSet-forof" , function ( ) {
43
- let card = 0 ;
44
- for ( const element of stb ) {
45
- card ++ ;
46
- }
47
- return card ;
48
- } )
49
- . add ( "SparseTypedFastBitSet-foreach" , function ( ) {
50
- let card = 0 ;
51
- const inc = function ( ) {
52
- card ++ ;
53
- } ;
54
- tb . forEach ( inc ) ;
55
- return card ;
56
- } )
31
+ . add ( "TypedFastBitSet-forof" , function ( ) {
32
+ let card = 0 ;
33
+ for ( const element of stb ) {
34
+ card ++ ;
35
+ }
36
+ return card ;
37
+ } )
38
+ . add ( "TypedFastBitSet-foreach" , function ( ) {
39
+ let card = 0 ;
40
+ const inc = function ( ) {
41
+ card ++ ;
42
+ } ;
43
+ tb . forEach ( inc ) ;
44
+ return card ;
45
+ } )
46
+ . add ( "SparseTypedFastBitSet-forof" , function ( ) {
47
+ let card = 0 ;
48
+ for ( const element of stb ) {
49
+ card ++ ;
50
+ }
51
+ return card ;
52
+ } )
53
+ . add ( "SparseTypedFastBitSet-foreach" , function ( ) {
54
+ let card = 0 ;
55
+ const inc = function ( ) {
56
+ card ++ ;
57
+ } ;
58
+ tb . forEach ( inc ) ;
59
+ return card ;
60
+ } )
61
+ . add ( "TypedFastBitSet-nested-forof" , function ( ) {
62
+ let card = 0 ;
63
+ for ( const x of tb_small ) {
64
+ for ( const y of tb_small ) {
65
+ for ( const z of tb_small ) {
66
+ card += x + y + z ;
67
+ }
68
+ }
69
+ }
70
+ return card ;
71
+ } )
72
+ . add ( "TypedFastBitSet-nested-forEach" , function ( ) {
73
+ let card = 0 ;
74
+ tb_small . forEach ( function ( x ) {
75
+ tb_small . forEach ( function ( y ) {
76
+ tb_small . forEach ( function ( z ) {
77
+ card += x + y + z ;
78
+ } ) ;
79
+ } ) ;
80
+ } ) ;
81
+ return card ;
82
+ } )
57
83
// add listeners
58
84
. on ( "cycle" , function ( event ) {
59
85
console . log ( String ( event . target ) ) ;
@@ -62,7 +88,6 @@ function ForEachBench() {
62
88
. run ( { async : false } ) ;
63
89
}
64
90
65
-
66
91
const main = function ( ) {
67
92
console . log (
68
93
"Platform: " + process . platform + " " + os . release ( ) + " " + process . arch
0 commit comments