benchmark.js 781 B

1234567891011121314151617181920212223242526
  1. 'use strict'
  2. const Benchmark = require('benchmark')
  3. const scmp = require('../')
  4. // `safe-buffer` in case `Buffer.from` in newer versions of node aren't available
  5. const Buffer = require('safe-buffer').Buffer
  6. const HASH1 = Buffer.from('e727d1464ae12436e899a726da5b2f11d8381b26', 'hex')
  7. const HASH2 = Buffer.from('f727d1464ae12436e899a726da5b2f11d8381b26', 'hex')
  8. const suite = new Benchmark.Suite()
  9. suite.add('short-circuit compares', function () {
  10. // eslint-disable-next-line no-unused-expressions
  11. HASH1 === HASH2
  12. })
  13. .add('scmp compares', function () {
  14. scmp(HASH1, HASH2)
  15. })
  16. .on('cycle', function (event) {
  17. console.log(String(event.target))
  18. })
  19. .on('complete', function () {
  20. console.log('Fastest is ' + this.filter('fastest').map('name'))
  21. })
  22. .run()