title: How To Measure PBKDF2 SHA256 Hash Computation Time
body: <p>I need to measure how long it takes to compute my hash with x number of iterations. Here is code:</p>
  
  <pre><code> function hashPromise(secretPhrase, keylen) {
   let hashedKey
   var promise = new Promise(function(resolve, reject) {
      crypto.pbkdf2(secretPhrase, 'salt', keylen, 256, 
      'sha256', (err, key) =&gt; {
          if (err) {
              console.log(err)
              reject(err);
          } else {
              hashedKey = key.toString('hex')
              let time = new Date().getTime()
              console.log('keylen: ' + keylen)
              console.log('TIMESTAMP Hash Finished: ' + time)
              console.log('hashedKey: ' + hashedKey)
              resolve( hashedSSN )
          }
        })
    })
  
  return promise;
  }
  </code></pre>
  
  <p>I am looping through this function with promise.all a couple hundred times, passing in a new secretPhrase each time.</p>
  
  <p>I am using a Firebase Functions http request to trigger this functions. Here are my logs when keylen is 1000:</p>
  
  <p><a href="https://i.stack.imgur.com/yZqZ4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yZqZ4.png" alt="enter image description here"></a></p>
  
  <p>And here are my logs if keylen is 500000</p>
  
  <p><a href="https://i.stack.imgur.com/w4enD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w4enD.png" alt="enter image description here"></a></p>
  
  <p>Would computation time simply be the difference between each 'TIMESTAMP Hash Finished'? Or would it be the time it took the entire function to finish (at top of logs)? </p>
  
  <p>Ie- Computation time using a 500000 keylen is 1526473894031 - 1526473893718 = 313ms ?</p>