index.js 726 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var timeSafeCompare = require('../../lib/index');
  3. function random(length) {
  4. length = length || 32;
  5. var result = "";
  6. var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-+/*[]{}-=\|;\':\"<>?,./";
  7. for( var i=0; i < length; i++ ){
  8. result += possible.charAt(Math.floor(Math.random() * possible.length));
  9. }
  10. return result;
  11. }
  12. function run(count) {
  13. count = count || 100*1000;
  14. console.log('benchmark count: ' + count/1000 + 'k');
  15. console.time('benchmark');
  16. while(count--){
  17. timeSafeCompare(random(), random());
  18. }
  19. console.timeEnd('benchmark');
  20. }
  21. run(100000);
  22. module.exports = run;