mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
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.
This commit is contained in:
parent
d11088eb43
commit
e3ddc2bcc4
7 changed files with 161 additions and 1 deletions
13
jsTestDriver-perf.conf
Normal file
13
jsTestDriver-perf.conf
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
server: http://localhost:9876
|
||||
|
||||
load:
|
||||
- lib/jasmine-1.0.1/jasmine.js
|
||||
- lib/jasmine-jstd-adapter/JasmineAdapter.js
|
||||
- lib/jquery/jquery-1.4.2.js
|
||||
- test/jquery_remove.js
|
||||
- build/angular.min.js
|
||||
- perf/data/*.js
|
||||
- perf/testUtils.js
|
||||
- perf/*.js
|
||||
|
||||
exclude:
|
||||
10
perf/data/jsonParserPayload.js
Normal file
10
perf/data/jsonParserPayload.js
Normal file
File diff suppressed because one or more lines are too long
49
perf/data/jsonParserPayload.rb
Normal file
49
perf/data/jsonParserPayload.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
def generate_object(f, objName, iterations)
|
||||
f.write("var #{objName}='[");
|
||||
|
||||
iterations.times do |i|
|
||||
f.write('{')
|
||||
|
||||
f.write('"simpleStringProperty":') #23
|
||||
f.write('"some string value ' + ('%07d' % i) + '"') #27
|
||||
f.write(',')
|
||||
|
||||
f.write('"stringWithQuotes":') #19
|
||||
f.write('"some string with \\\\"quotes\\\\" ' + ('%07d' % i) + '"') #36
|
||||
f.write(',')
|
||||
|
||||
f.write('"stringWithUnicode":')
|
||||
f.write('"short string with \\u1234 unicode \\u2345 chars ' + ('%07d' % i) + '"')
|
||||
f.write(',')
|
||||
|
||||
f.write('"aNumber":') #10
|
||||
f.write(i) #?
|
||||
f.write(',')
|
||||
|
||||
f.write('"smallArray":')
|
||||
f.write('["a",23,"b",42,' + i.to_s + ']')
|
||||
f.write(',')
|
||||
|
||||
f.write('"smallObj":')
|
||||
f.write('{"foo":"bar","baz":543,"num":' + i.to_s + ',"fuz":"fuz buz huz duz ' + i.to_s + '"}')
|
||||
f.write(',')
|
||||
|
||||
f.write('"timeStamp":')
|
||||
f.write('"2010-12-22T04:58:01.' + ("%03d" % (i%1000)) + '"')
|
||||
|
||||
f.write('},')
|
||||
end
|
||||
|
||||
f.write('"just a padding string"]\';' + "\n\n");
|
||||
end
|
||||
|
||||
file_path = File.join(File.dirname(__FILE__), 'jsonParserPayload.js')
|
||||
|
||||
File.open(file_path, 'w') do |f|
|
||||
generate_object(f, 'superTinyJsonString', 1) #~300b
|
||||
generate_object(f, 'tinyJsonString', 3) #~1kb
|
||||
generate_object(f, 'smallJsonString', 30) #~10kb
|
||||
generate_object(f, 'mediumJsonString', 600) #~200kb
|
||||
generate_object(f, 'largeJsonString', 2000) #~650kb
|
||||
end
|
||||
|
||||
55
perf/jsonPerfSpec.js
Normal file
55
perf/jsonPerfSpec.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
describe('json', function() {
|
||||
xit('should parse json in a reasonable time', function() {
|
||||
var totalSubstr = 0,
|
||||
totalGetMatch = 0,
|
||||
totalConsume = 0,
|
||||
totalTime = 0,
|
||||
runTimes = [];
|
||||
|
||||
for (var i=0; i<10; i++) {
|
||||
window.substrTime = 0;
|
||||
window.getMatchTime = 0;
|
||||
window.consumeTime = 0;
|
||||
var start = Date.now();
|
||||
expect(angular.fromJson(largeJsonString)).toBeTruthy();
|
||||
var time = Date.now() - start;
|
||||
// dump('parse time', time, 'consume', window.consumeTime,
|
||||
// 'substr', window.substrTime,
|
||||
// 'getMatch', window.getMatchTime);
|
||||
totalTime += time;
|
||||
totalSubstr += window.substrTime;
|
||||
totalGetMatch += window.getMatchTime;
|
||||
totalConsume += window.consumeTime;
|
||||
runTimes.push(time);
|
||||
}
|
||||
|
||||
totalGetMatch = totalGetMatch - totalSubstr;
|
||||
|
||||
dump("totals", totalTime,
|
||||
"| consume", totalConsume, '' + Math.round(totalConsume/(totalTime/100)) + '%',
|
||||
"| substr", totalSubstr, '' + Math.round(totalSubstr/(totalTime/100)) + '%',
|
||||
"| getMatch", totalGetMatch, '' + Math.round(totalGetMatch/(totalTime/100)) + '%');
|
||||
dump("run times", runTimes);
|
||||
delete window.consumeTime;
|
||||
delete window.substrTime;
|
||||
delete window.getMatchTime;
|
||||
});
|
||||
|
||||
|
||||
it('angular parser', function() {
|
||||
var duration = time(function() {
|
||||
expect(angular.fromJson(largeJsonString)).toBeTruthy();
|
||||
}, 1);
|
||||
|
||||
expect(duration).toBeLessThan(4000);
|
||||
});
|
||||
|
||||
|
||||
it('native json', function() {
|
||||
var duration = time(function() {
|
||||
expect(JSON.parse(largeJsonString)).toBeTruthy();
|
||||
}, 1);
|
||||
|
||||
expect(duration).toBeLessThan(200);
|
||||
});
|
||||
});
|
||||
20
perf/testUtils.js
Normal file
20
perf/testUtils.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
if (window.jstestdriver) {
|
||||
jstd = jstestdriver;
|
||||
dump = angular.bind(jstd.console, jstd.console.log);
|
||||
}
|
||||
|
||||
function time(fn, times) {
|
||||
times = times || 1;
|
||||
|
||||
var i,
|
||||
start,
|
||||
duration = 0;
|
||||
|
||||
for (i=0; i<times; i++) {
|
||||
start = Date.now();
|
||||
fn();
|
||||
duration += Date.now() - start;
|
||||
}
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 --browserTimeout 20000
|
||||
java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 --browserTimeout 90000
|
||||
|
|
|
|||
13
test-perf.sh
Executable file
13
test-perf.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
tests=$1
|
||||
norecompile=$2
|
||||
|
||||
if [[ $tests = "" ]]; then
|
||||
tests="all"
|
||||
fi
|
||||
|
||||
if [[ $norecompile = "" ]]; then
|
||||
rake compile
|
||||
fi
|
||||
|
||||
java -jar lib/jstestdriver/JsTestDriver.jar --tests "$tests" --config jsTestDriver-perf.conf
|
||||
Loading…
Reference in a new issue