Skip to content

Commit fab4ada

Browse files
committed
Created a performance test harness and reporter
1 parent d6eba8f commit fab4ada

8 files changed

+103
-43
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
3+
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
4+
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
5+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;resources&gt;&#10;&lt;item path=&quot;/angular.js/perf&quot; type=&quot;2&quot;/&gt;&#10;&lt;item path=&quot;/angular.js/src&quot; type=&quot;2&quot;/&gt;&#10;&lt;/resources&gt;}"/>
6+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/angular.js/perf.sh}"/>
7+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
8+
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
9+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/angular.js}"/>
10+
</launchConfiguration>

.project

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
</dictionary>
3131
</arguments>
3232
</buildCommand>
33+
<buildCommand>
34+
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
35+
<triggers>auto,full,incremental,</triggers>
36+
<arguments>
37+
<dictionary>
38+
<key>LaunchConfigHandle</key>
39+
<value>&lt;project&gt;/.externalToolBuilders/JSTD_perf.launch</value>
40+
</dictionary>
41+
</arguments>
42+
</buildCommand>
3343
</buildSpec>
3444
<natures>
3545
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>

jsTestDriver-coverage.conf

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ load:
2424

2525
exclude:
2626
- test/jquery_alias.js
27-
- src/angular.prefix
28-
- src/angular.suffix
2927
- src/angular-bootstrap.js
3028
- src/scenario/angular-bootstrap.js
3129
- src/AngularPublic.js

jsTestDriver-jquery.conf

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ load:
2323
- example/personalLog/test/*.js
2424

2525
exclude:
26-
- src/angular.prefix
27-
- src/angular.suffix
2826
- src/angular-bootstrap.js
2927
- src/AngularPublic.js
3028
- src/scenario/angular-bootstrap.js

jsTestDriver-perf.conf

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ server: http://localhost:9876
33
load:
44
- lib/jasmine-1.0.1/jasmine.js
55
- lib/jasmine-jstd-adapter/JasmineAdapter.js
6-
- lib/jquery/jquery-1.4.2.js
7-
- test/jquery_remove.js
8-
- build/angular.min.js
6+
- src/Angular.js
7+
- src/JSON.js
8+
- src/*.js
9+
- src/service/*.js
10+
- src/angular-mocks.js
911
- perf/data/*.js
1012
- perf/testUtils.js
1113
- perf/*.js
1214

1315
exclude:
16+
- src/angular-bootstrap.js
17+
- src/scenario/angular-bootstrap.js
18+
- src/AngularPublic.js

perf/jsonPerfSpec.js

+11-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
describe('json', function() {
22

33
it('angular parser', function() {
4-
var duration = time(function() {
5-
expect(angular.fromJson(largeJsonString)).toBeTruthy();
6-
}, 1);
7-
8-
dump(duration/1 + ' ms per iteration');
9-
});
10-
11-
12-
it('angular delegating to native parser', function() {
13-
var duration = time(function() {
14-
expect(angular.fromJson(largeJsonString, true)).toBeTruthy();
15-
}, 100);
16-
17-
dump(duration/100 + ' ms per iteration');
18-
});
19-
20-
21-
it('native json', function() {
22-
var duration = time(function() {
23-
expect(JSON.parse(largeJsonString)).toBeTruthy();
24-
}, 100);
25-
26-
dump(duration/100 + ' ms per iteration');
4+
perf(
5+
function angular() {
6+
fromJson(largeJsonString);
7+
},
8+
function nativeDelegate() {
9+
fromJson(largeJsonString, true);
10+
},
11+
function nativeJSON() {
12+
JSON.parse(largeJsonString);
13+
}
14+
);
2715
});
2816
});

perf/testUtils.js

+60-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,67 @@
11
if (window.jstestdriver) {
22
jstd = jstestdriver;
3-
dump = angular.bind(jstd.console, jstd.console.log);
3+
dump = bind(jstd.console, jstd.console.log);
44
}
55

6-
function time(fn, times) {
7-
times = times || 1;
6+
function time(fn) {
7+
var count = 1,
8+
targetTime = 500,
9+
start = new Date().getTime(),
10+
stop = start + targetTime,
11+
elapsed,
12+
end,
13+
iterations,
14+
pad = angularFilter.number;
815

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;
16+
// do one iteration to guess how long it will take
17+
fn();
18+
while((end=new Date().getTime()) < stop ){
19+
// how much time has elapsed since we started the test
20+
elapsed = (end-start) || 1;
21+
// guess how many more iterations we need before we reach
22+
// the time limit. We do this so that we spend most of our
23+
// time in tight loop
24+
iterations = Math.ceil(
25+
// how much more time we need
26+
(targetTime - elapsed)
27+
/
28+
2 // to prevent overrun guess low
29+
/
30+
// this is how much the cost is so far per iteration
31+
(elapsed / count)
32+
);
33+
count += iterations;
34+
while(iterations--) {
35+
fn();
36+
}
1737
}
38+
elapsed = end - start;
39+
return {
40+
count: count,
41+
total: elapsed,
42+
time: elapsed / count,
43+
name: fn.name,
44+
msg: '' + pad(elapsed / count, 3)
45+
+ ' ms [ ' + pad(1 / elapsed * count * 1000, 0) + ' ops/sec ] '
46+
+ '(' + elapsed + ' ms/' + count + ')'
47+
};
48+
49+
}
1850

19-
return duration;
20-
}
51+
function perf() {
52+
var log = [],
53+
summary = [],
54+
i,
55+
baseline,
56+
pad = angularFilter.number;
57+
58+
for (i = 0; i < arguments.length; i++) {
59+
var fn = arguments[i];
60+
var info = time(fn);
61+
if (baseline === undefined) baseline = info.time;
62+
summary.push(info.name + ': ' + pad(baseline / info.time, 2) + ' X');
63+
log.push('\n ' + info.name + ': ' + info.msg);
64+
}
65+
log.unshift(summary.join(' - '));
66+
dump(log.join(' '));
67+
}

test-reset.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
tests=$1
3+
4+
java -jar lib/jstestdriver/JsTestDriver.jar --tests all --reset

0 commit comments

Comments
 (0)