@@ -49,6 +49,7 @@ export namespace Measurement {
49
49
export interface Timing {
50
50
options : Options ;
51
51
computeTimeMs : number ;
52
+ hashCost : number ;
52
53
}
53
54
54
55
export interface TimingResult {
@@ -119,7 +120,8 @@ export namespace Measurement {
119
120
120
121
lastTiming = {
121
122
computeTimeMs : msElapsed ,
122
- options : _ . clone ( opts )
123
+ options : _ . clone ( opts ) ,
124
+ hashCost : opts . memoryCost * opts . parallelism * opts . timeCost
123
125
} ;
124
126
125
127
context . pendingResult . timings . push ( lastTiming ) ;
@@ -256,12 +258,13 @@ export namespace Measurement {
256
258
plain : "this is a super cool password" ,
257
259
saltLength : 16 ,
258
260
statusCallback : t => {
259
- const ms = `Hashing took ${ t . computeTimeMs } ms.` ;
260
- const pc = `Parallelism: ${ t . options . parallelism } .` ;
261
- const mc = `MemoryCost: ${ t . options . memoryCost } (${ Math . pow ( 2 , t . options . memoryCost ) / 1024 } MB).` ;
262
- const tc = `TimeCost: ${ t . options . timeCost } .` ;
261
+ const ms = `Hashed in ${ t . computeTimeMs } ms.` ;
262
+ const hc = `Cost: ${ t . hashCost } .` ;
263
+ const pc = `P: ${ t . options . parallelism } .` ;
264
+ const mc = `M: ${ t . options . memoryCost } (${ Math . pow ( 2 , t . options . memoryCost ) / 1024 } MB).` ;
265
+ const tc = `T: ${ t . options . timeCost } .` ;
263
266
264
- console . log ( `${ ms } ${ pc } ${ mc } ${ tc } ` ) ;
267
+ console . log ( `${ ms } ${ hc } ${ pc } ${ mc } ${ tc } ` ) ;
265
268
266
269
return true ;
267
270
}
@@ -323,7 +326,7 @@ export namespace Selection {
323
326
324
327
// No options available...
325
328
if ( ! timing ) {
326
- throw new Error ( `No timings found with less than ${ maxTimeMs } ms compute time.` ) ;
329
+ return this . fastest ( ) ;
327
330
}
328
331
329
332
this . timingsCache [ maxTimeMs ] = timing ;
@@ -345,8 +348,8 @@ export namespace Selection {
345
348
346
349
getSortedTimings ( timings : Timing [ ] ) : Timing [ ] {
347
350
return _ . orderBy ( timings ,
348
- [ "options.memoryCost" , "options.timeCost" , "options.parallelism ", "computeTimeMs" ] ,
349
- [ "asc" , "asc" , "asc" , "asc" ] ) ;
351
+ [ "hashCost " , "computeTimeMs" ] ,
352
+ [ "asc" , "asc" ] ) ;
350
353
}
351
354
}
352
355
0 commit comments