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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
sjcl.perf = { all: {} };
sjcl.perf.PerfCase = function PerfCase (name, cases, runCase) {
this.name = name;
this.cases = cases;
this.runCase = runCase;
sjcl.perf.all[name] = this;
};
sjcl.perf.PerfCase.prototype.run = function (callback) {
var thiz = this;
var repo = browserUtil.write("info", "Running " + this.name + "...");
var table = browserUtil.writeTable(["iter", "time"]);
thiz.runCase(this.cases[0]); // cold start
browserUtil.cpsMap(function (t, i, n, cb) {
var runs = [];
// do 3 runs and average them
for (var k = 0; k < 3; k++) {
var t0 = performance.now();
thiz.runCase(t);
var t1 = performance.now();
runs.push(t1 - t0);
}
var avg = runs.reduce(function(a, b) { return a + b; }) / runs.length;
table.update([t, avg.toFixed(3) + ' ms']);
cb && cb();
}, this.cases, true, function() {
repo.update("pass", "done.");
callback();
});
};
sjcl.perf.run = function (perfs, callback) {
browserUtil.status("Profiling...");
var t;
if (perfs === undefined || perfs.length == 0) {
perfs = [];
for (t in sjcl.perf.all) {
if (sjcl.perf.all.hasOwnProperty(t)) {
perfs.push(t);
}
}
}
browserUtil.cpsMap(function (t, i, n, cb) {
sjcl.perf.all[perfs[i]].run(cb);
}, perfs, true, callback);
};
// performance case for pbkdf2
var cases = [1000, 2000, 4000, 8000, 16000, 32000, 48000, 64000];
new sjcl.perf.PerfCase("pbkdf2", cases,
function (iter) {
sjcl.misc.pbkdf2("mypassword", "01234567890123456789", iter);
}
);
sjcl.perf.run([], function() {
browserUtil.status("");
});
|