src/sm3.js
// Measures and prints MB/second hash performance each time

Measures and prints MB/second hash performance each time
Measures and prints MB / second hash performance each time
function testSpeed (hashFn, N, M) {
  let startMs = new Date().getTime()
  const input = new Uint8Array(N)
  for (let i = 0; i < N; i++) {
    input[i] = i % 256
  }
  const genMs = new Date().getTime()
  console.log('Generated random input in ' + (genMs - startMs) + 'ms')
  startMs = genMs
  for (let i = 0; i < M; i++) {
    const hashHex = hashFn(input)
    const hashMs = new Date().getTime()
    const ms = hashMs - startMs
    startMs = hashMs
    console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...')
    console.log(Math.round(N / (1 << 20) / (ms / 1000) * 100) / 100 + ' MB PER SECOND')
  }
}
function testSpeed ( hashFn , N , M ) { let startMs = new Date ( ) . getTime ( ) const input = new Uint8Array ( N ) for ( let i = 0 ; i < N ; i ++ ) { input [ i ] = i % 256 } const genMs = new Date ( ) . getTime ( ) console . log ( 'Generated random input in ' + ( genMs - startMs ) + 'ms' ) startMs = genMs for ( let i = 0 ; i < M ; i ++ ) { const hashHex = hashFn ( input ) const hashMs = new Date ( ) . getTime ( ) const ms = hashMs - startMs startMs = hashMs console . log ( 'Hashed in ' + ms + 'ms: ' + hashHex . substring ( 0 , 20 ) + '...' ) console . log ( Math . round ( N / ( 1 << 20 ) / ( ms / 1000 ) * 100 ) / 100 + ' MB PER SECOND' ) } }
Measures and prints MB/second hash performance each time
Measures and prints MB / second hash performance each time