-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.js
38 lines (31 loc) · 937 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
var uid = require('./index');
var assert = require('assert');
var freqs = {};
var ITERATIONS = 1000000;
var LENGTH = 64;
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
var i;
for (i = 0; i < chars.length; i++) {
freqs[chars[i]] = 0;
}
console.log("Running", ITERATIONS, "iterations...");
console.time("Duration");
while(ITERATIONS--) {
var str = uid(LENGTH);
for (var i = 0; i < str.length; i++) {
freqs[str[i]]++;
}
}
console.log("Done. Distribution:");
console.log(JSON.stringify(freqs, undefined, 2));
console.timeEnd("Duration");
var vals = Object.keys(freqs).map(function(key) {
return freqs[key];
});
var min = Math.min.apply(null, vals);
var max = Math.max.apply(null, vals);
console.log("Min freq:", min, "Max freq:", max);
var diffPcnt = Math.abs(min / max - 1) * 100;
console.log("Min and max frequencies are " + diffPcnt + "% apart.");
assert(diffPcnt < 1);