@@ -98,6 +98,15 @@ function testMapOperations(map) {
9898 }
9999}
100100
101+ function printSortedResults ( benchmark ) {
102+ console . log ( '\n======== Results ========' ) ;
103+ const results = Object . values ( benchmark ) . filter ( b => b && b . name ) ;
104+ const sortedResults = results . sort ( ( a , b ) => b . hz - a . hz ) ;
105+ sortedResults . forEach ( ( b ) => {
106+ console . log ( `${ b . hz . toLocaleString ( ) } ops/s with ${ b . name } ` ) ;
107+ } ) ;
108+ }
109+
101110function useBenchmark ( ) {
102111 var suite = new Benchmark . Suite ;
103112 const NaiveHMLength = require ( '../src/data-structures/hash-maps/hash-map-1' ) ;
@@ -118,10 +127,14 @@ function useBenchmark() {
118127
119128 let map ;
120129
121- suite . add ( 'HashMap' , function ( ) {
122- map = new HashMap ( ) ;
123- testMapOperations ( map ) ;
124- } )
130+ suite
131+
132+ /*
133+ ======== Results ========
134+ 490.84 ops/s with HashMap
135+ 293.756 ops/s with HashMap3
136+ 64.091 ops/s with HashMap4
137+ */
125138
126139 // HashMap3 x 543 ops/sec ±1.53% (84 runs sampled)
127140 suite . add ( 'HashMap3' , function ( ) {
@@ -135,6 +148,11 @@ function useBenchmark() {
135148 testMapOperations ( map ) ;
136149 } )
137150
151+ . add ( 'HashMap' , function ( ) {
152+ map = new HashMap ( ) ;
153+ testMapOperations ( map ) ;
154+ } )
155+
138156 // add listeners
139157 . on ( 'cycle' , function ( event ) {
140158 console . log ( String ( event . target ) ) ;
@@ -148,6 +166,7 @@ function useBenchmark() {
148166 . on ( 'complete' , function ( ) {
149167 console . log ( 'Fastest is ' + this . filter ( 'fastest' ) . map ( 'name' ) ) ;
150168 // console.log('Slowest is ' + this.filter('slowest').map('name'));
169+ printSortedResults ( this ) ;
151170 } )
152171 // run async
153172 . run ( { 'async' : true } ) ;
0 commit comments