Created
November 6, 2013 12:59
-
-
Save rlidwka/7335696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cookie = require('./') | |
var acc, x; | |
console.log(x = cookie.sign('hello', 'test')) | |
function quantile(arr, from, to) { | |
from = Math.floor((arr.length) * from) | |
to = Math.ceil((arr.length) * to) | |
var s = 0 | |
arr = arr.sort() | |
for (var x=from; x<to; x++) { | |
s += arr[x] | |
} | |
return ~~(s/(to-from)) | |
} | |
function shuffle(o){ | |
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); | |
return o; | |
} | |
var iterations = 100000 // <-- change this to slow down/speed up test | |
var sums = {} | |
var arr = [] | |
var sum_all = [0,0] | |
for (var z=0;; z++) { | |
shuffle([10, 15, 20, 25, 30, 35, 40, 45]).forEach(function(str) { | |
var n = x.split('') | |
n[str] = '_' | |
n = n.join('') | |
var d = process.hrtime() | |
for (var i=0; i<iterations; i++) { | |
//acc = cookie.unsign(n, 'test') | |
acc = n === x ? n : false | |
} | |
var diff = process.hrtime(d) | |
var time = diff[0] * 1e9 + diff[1] | |
arr[str] = arr[str] || [] | |
arr[str].push(time) | |
console.log(str, n, time) | |
sum_all[0]++ | |
sum_all[1] += time | |
}) | |
;[10, 15, 20, 25, 30, 35, 40, 45].forEach(function(str) { | |
console.log('|', str, quantile(arr[str], 0.2, 0.8), [0/5,1/5,2/5,3/5,4/5].map(function(x) {return quantile(arr[str], x, x + 1/5)})) | |
}) | |
console.log('= iterations:', sum_all[0] * iterations, ', time=', ~~(sum_all[1]/1000000000), 'sec') | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment