File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -30,4 +30,29 @@ describe('queue performance', () => {
30
30
console . log ( `Queue time: ${ totalQueue [ 0 ] + totalQueue [ 1 ] / 1e9 } ` ) ;
31
31
expect ( totalArray [ 0 ] + totalArray [ 1 ] / 1e9 > ( totalQueue [ 0 ] + totalQueue [ 1 ] / 1e9 ) * 100 ) . to . be . true ;
32
32
} ) ;
33
+
34
+ it ( 'the time difference between array.shift and queue.shift should be irrelevant for small lengths' , ( ) => {
35
+ const array = [ ] ;
36
+ const queue = new Queue ( ) ;
37
+ for ( let i = 1 ; i < 10000 ; i ++ ) {
38
+ array . push ( i ) ;
39
+ queue . push ( i ) ;
40
+ }
41
+
42
+
43
+ const startQueue = process . hrtime ( ) ;
44
+ while ( queue . length > 0 ) {
45
+ queue . shift ( ) ;
46
+ }
47
+ const totalQueue = process . hrtime ( startQueue ) ;
48
+ const startArray = process . hrtime ( ) ;
49
+ while ( array . length > 0 ) {
50
+ array . shift ( ) ;
51
+ }
52
+ const totalArray = process . hrtime ( startArray ) ;
53
+
54
+ console . log ( `Array time: ${ totalArray [ 0 ] + totalArray [ 1 ] / 1e9 } ` ) ;
55
+ console . log ( `Queue time: ${ totalQueue [ 0 ] + totalQueue [ 1 ] / 1e9 } ` ) ;
56
+ expect ( totalArray [ 0 ] + totalArray [ 1 ] / 1e9 - ( totalQueue [ 0 ] + totalQueue [ 1 ] / 1e9 ) < 0.001 ) . to . be . true ;
57
+ } ) ;
33
58
} )
You can’t perform that action at this time.
0 commit comments