Skip to content

Commit e3ddc2b

Browse files
committed
simple perf testing harness with JSON parsing tests
- all tests should be under perf/ - all payloads should be under perf/data - run tests with ./server.sh + ./test-perf.sh We still lack a way to compare results against a baseline, but this is better than nothing.
1 parent d11088e commit e3ddc2b

7 files changed

Lines changed: 161 additions & 1 deletion

File tree

jsTestDriver-perf.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
server: http://localhost:9876
2+
3+
load:
4+
- lib/jasmine-1.0.1/jasmine.js
5+
- lib/jasmine-jstd-adapter/JasmineAdapter.js
6+
- lib/jquery/jquery-1.4.2.js
7+
- test/jquery_remove.js
8+
- build/angular.min.js
9+
- perf/data/*.js
10+
- perf/testUtils.js
11+
- perf/*.js
12+
13+
exclude:

perf/data/jsonParserPayload.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

perf/data/jsonParserPayload.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
def generate_object(f, objName, iterations)
2+
f.write("var #{objName}='[");
3+
4+
iterations.times do |i|
5+
f.write('{')
6+
7+
f.write('"simpleStringProperty":') #23
8+
f.write('"some string value ' + ('%07d' % i) + '"') #27
9+
f.write(',')
10+
11+
f.write('"stringWithQuotes":') #19
12+
f.write('"some string with \\\\"quotes\\\\" ' + ('%07d' % i) + '"') #36
13+
f.write(',')
14+
15+
f.write('"stringWithUnicode":')
16+
f.write('"short string with \\u1234 unicode \\u2345 chars ' + ('%07d' % i) + '"')
17+
f.write(',')
18+
19+
f.write('"aNumber":') #10
20+
f.write(i) #?
21+
f.write(',')
22+
23+
f.write('"smallArray":')
24+
f.write('["a",23,"b",42,' + i.to_s + ']')
25+
f.write(',')
26+
27+
f.write('"smallObj":')
28+
f.write('{"foo":"bar","baz":543,"num":' + i.to_s + ',"fuz":"fuz buz huz duz ' + i.to_s + '"}')
29+
f.write(',')
30+
31+
f.write('"timeStamp":')
32+
f.write('"2010-12-22T04:58:01.' + ("%03d" % (i%1000)) + '"')
33+
34+
f.write('},')
35+
end
36+
37+
f.write('"just a padding string"]\';' + "\n\n");
38+
end
39+
40+
file_path = File.join(File.dirname(__FILE__), 'jsonParserPayload.js')
41+
42+
File.open(file_path, 'w') do |f|
43+
generate_object(f, 'superTinyJsonString', 1) #~300b
44+
generate_object(f, 'tinyJsonString', 3) #~1kb
45+
generate_object(f, 'smallJsonString', 30) #~10kb
46+
generate_object(f, 'mediumJsonString', 600) #~200kb
47+
generate_object(f, 'largeJsonString', 2000) #~650kb
48+
end
49+

perf/jsonPerfSpec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
describe('json', function() {
2+
xit('should parse json in a reasonable time', function() {
3+
var totalSubstr = 0,
4+
totalGetMatch = 0,
5+
totalConsume = 0,
6+
totalTime = 0,
7+
runTimes = [];
8+
9+
for (var i=0; i<10; i++) {
10+
window.substrTime = 0;
11+
window.getMatchTime = 0;
12+
window.consumeTime = 0;
13+
var start = Date.now();
14+
expect(angular.fromJson(largeJsonString)).toBeTruthy();
15+
var time = Date.now() - start;
16+
// dump('parse time', time, 'consume', window.consumeTime,
17+
// 'substr', window.substrTime,
18+
// 'getMatch', window.getMatchTime);
19+
totalTime += time;
20+
totalSubstr += window.substrTime;
21+
totalGetMatch += window.getMatchTime;
22+
totalConsume += window.consumeTime;
23+
runTimes.push(time);
24+
}
25+
26+
totalGetMatch = totalGetMatch - totalSubstr;
27+
28+
dump("totals", totalTime,
29+
"| consume", totalConsume, '' + Math.round(totalConsume/(totalTime/100)) + '%',
30+
"| substr", totalSubstr, '' + Math.round(totalSubstr/(totalTime/100)) + '%',
31+
"| getMatch", totalGetMatch, '' + Math.round(totalGetMatch/(totalTime/100)) + '%');
32+
dump("run times", runTimes);
33+
delete window.consumeTime;
34+
delete window.substrTime;
35+
delete window.getMatchTime;
36+
});
37+
38+
39+
it('angular parser', function() {
40+
var duration = time(function() {
41+
expect(angular.fromJson(largeJsonString)).toBeTruthy();
42+
}, 1);
43+
44+
expect(duration).toBeLessThan(4000);
45+
});
46+
47+
48+
it('native json', function() {
49+
var duration = time(function() {
50+
expect(JSON.parse(largeJsonString)).toBeTruthy();
51+
}, 1);
52+
53+
expect(duration).toBeLessThan(200);
54+
});
55+
});

perf/testUtils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
if (window.jstestdriver) {
2+
jstd = jstestdriver;
3+
dump = angular.bind(jstd.console, jstd.console.log);
4+
}
5+
6+
function time(fn, times) {
7+
times = times || 1;
8+
9+
var i,
10+
start,
11+
duration = 0;
12+
13+
for (i=0; i<times; i++) {
14+
start = Date.now();
15+
fn();
16+
duration += Date.now() - start;
17+
}
18+
19+
return duration;
20+
}

server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 --browserTimeout 20000
3+
java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 --browserTimeout 90000

test-perf.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
tests=$1
3+
norecompile=$2
4+
5+
if [[ $tests = "" ]]; then
6+
tests="all"
7+
fi
8+
9+
if [[ $norecompile = "" ]]; then
10+
rake compile
11+
fi
12+
13+
java -jar lib/jstestdriver/JsTestDriver.jar --tests "$tests" --config jsTestDriver-perf.conf

0 commit comments

Comments
 (0)