-
Notifications
You must be signed in to change notification settings - Fork 6
/
benchmark.js
60 lines (55 loc) · 1.39 KB
/
benchmark.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(function () {
"use strict";
var samples = (function () {
var result = [];
var size = 1000;
var evilchars = "().#,";
var i = 0;
var text;
while (size > 0) {
text = "foo bar #hashtag http://www.google.com/lol";
for(i=0; i < size; i++) {
text += evilchars.charAt(Math.floor(Math.random() * evilchars.length));
}
result.push(text);
size--;
}
return result;
}());
var suite = new Benchmark.Suite;
suite
.add("All", function() {
var i;
for (var i = samples.length; i >= 0; i--) {
FlowdockText.extractAll(samples[i]);
}
})
.add("Long: 1000 evil chars", function() {
FlowdockText.extractAll(samples[0]);
})
.add("Short: 100 evil chars", function() {
FlowdockText.extractAll(samples[900]);
})
.add("Nice: 0 evil chars", function() {
FlowdockText.extractAll(samples[999]);
})
.add("parseTags: all", function() {
var i;
for (var i = samples.length; i >= 0; i--) {
FlowdockText.parseTags(samples[i]);
}
})
.add("parseTags: 1000 evil chars", function() {
FlowdockText.parseTags(samples[0]);
})
.add("parseTags: 100 evil chars", function() {
FlowdockText.parseTags(samples[900]);
})
.add("parseTags: 0 evil chars", function() {
FlowdockText.parseTags(samples[999]);
})
.on("cycle", function(event) {
console.log(String(event.target));
})
.run();
}());