mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-25 06:13:44 +00:00
Created a performance test harness and reporter
This commit is contained in:
parent
d6eba8f39f
commit
fab4ada3c8
8 changed files with 103 additions and 43 deletions
10
.externalToolBuilders/JSTD_perf.launch
Normal file
10
.externalToolBuilders/JSTD_perf.launch
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
|
||||||
|
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources> <item path="/angular.js/perf" type="2"/> <item path="/angular.js/src" type="2"/> </resources>}"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/angular.js/perf.sh}"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/angular.js}"/>
|
||||||
|
</launchConfiguration>
|
||||||
10
.project
10
.project
|
|
@ -30,6 +30,16 @@
|
||||||
</dictionary>
|
</dictionary>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||||
|
<triggers>auto,full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
<dictionary>
|
||||||
|
<key>LaunchConfigHandle</key>
|
||||||
|
<value><project>/.externalToolBuilders/JSTD_perf.launch</value>
|
||||||
|
</dictionary>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ load:
|
||||||
|
|
||||||
exclude:
|
exclude:
|
||||||
- test/jquery_alias.js
|
- test/jquery_alias.js
|
||||||
- src/angular.prefix
|
|
||||||
- src/angular.suffix
|
|
||||||
- src/angular-bootstrap.js
|
- src/angular-bootstrap.js
|
||||||
- src/scenario/angular-bootstrap.js
|
- src/scenario/angular-bootstrap.js
|
||||||
- src/AngularPublic.js
|
- src/AngularPublic.js
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ load:
|
||||||
- example/personalLog/test/*.js
|
- example/personalLog/test/*.js
|
||||||
|
|
||||||
exclude:
|
exclude:
|
||||||
- src/angular.prefix
|
|
||||||
- src/angular.suffix
|
|
||||||
- src/angular-bootstrap.js
|
- src/angular-bootstrap.js
|
||||||
- src/AngularPublic.js
|
- src/AngularPublic.js
|
||||||
- src/scenario/angular-bootstrap.js
|
- src/scenario/angular-bootstrap.js
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,16 @@ server: http://localhost:9876
|
||||||
load:
|
load:
|
||||||
- lib/jasmine-1.0.1/jasmine.js
|
- lib/jasmine-1.0.1/jasmine.js
|
||||||
- lib/jasmine-jstd-adapter/JasmineAdapter.js
|
- lib/jasmine-jstd-adapter/JasmineAdapter.js
|
||||||
- lib/jquery/jquery-1.4.2.js
|
- src/Angular.js
|
||||||
- test/jquery_remove.js
|
- src/JSON.js
|
||||||
- build/angular.min.js
|
- src/*.js
|
||||||
|
- src/service/*.js
|
||||||
|
- src/angular-mocks.js
|
||||||
- perf/data/*.js
|
- perf/data/*.js
|
||||||
- perf/testUtils.js
|
- perf/testUtils.js
|
||||||
- perf/*.js
|
- perf/*.js
|
||||||
|
|
||||||
exclude:
|
exclude:
|
||||||
|
- src/angular-bootstrap.js
|
||||||
|
- src/scenario/angular-bootstrap.js
|
||||||
|
- src/AngularPublic.js
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,16 @@
|
||||||
describe('json', function() {
|
describe('json', function() {
|
||||||
|
|
||||||
it('angular parser', function() {
|
it('angular parser', function() {
|
||||||
var duration = time(function() {
|
perf(
|
||||||
expect(angular.fromJson(largeJsonString)).toBeTruthy();
|
function angular() {
|
||||||
}, 1);
|
fromJson(largeJsonString);
|
||||||
|
},
|
||||||
dump(duration/1 + ' ms per iteration');
|
function nativeDelegate() {
|
||||||
});
|
fromJson(largeJsonString, true);
|
||||||
|
},
|
||||||
|
function nativeJSON() {
|
||||||
it('angular delegating to native parser', function() {
|
JSON.parse(largeJsonString);
|
||||||
var duration = time(function() {
|
}
|
||||||
expect(angular.fromJson(largeJsonString, true)).toBeTruthy();
|
);
|
||||||
}, 100);
|
|
||||||
|
|
||||||
dump(duration/100 + ' ms per iteration');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('native json', function() {
|
|
||||||
var duration = time(function() {
|
|
||||||
expect(JSON.parse(largeJsonString)).toBeTruthy();
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
dump(duration/100 + ' ms per iteration');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,67 @@
|
||||||
if (window.jstestdriver) {
|
if (window.jstestdriver) {
|
||||||
jstd = jstestdriver;
|
jstd = jstestdriver;
|
||||||
dump = angular.bind(jstd.console, jstd.console.log);
|
dump = bind(jstd.console, jstd.console.log);
|
||||||
}
|
}
|
||||||
|
|
||||||
function time(fn, times) {
|
function time(fn) {
|
||||||
times = times || 1;
|
var count = 1,
|
||||||
|
targetTime = 500,
|
||||||
|
start = new Date().getTime(),
|
||||||
|
stop = start + targetTime,
|
||||||
|
elapsed,
|
||||||
|
end,
|
||||||
|
iterations,
|
||||||
|
pad = angularFilter.number;
|
||||||
|
|
||||||
var i,
|
// do one iteration to guess how long it will take
|
||||||
start,
|
fn();
|
||||||
duration = 0;
|
while((end=new Date().getTime()) < stop ){
|
||||||
|
// how much time has elapsed since we started the test
|
||||||
for (i=0; i<times; i++) {
|
elapsed = (end-start) || 1;
|
||||||
start = Date.now();
|
// guess how many more iterations we need before we reach
|
||||||
fn();
|
// the time limit. We do this so that we spend most of our
|
||||||
duration += Date.now() - start;
|
// time in tight loop
|
||||||
|
iterations = Math.ceil(
|
||||||
|
// how much more time we need
|
||||||
|
(targetTime - elapsed)
|
||||||
|
/
|
||||||
|
2 // to prevent overrun guess low
|
||||||
|
/
|
||||||
|
// this is how much the cost is so far per iteration
|
||||||
|
(elapsed / count)
|
||||||
|
);
|
||||||
|
count += iterations;
|
||||||
|
while(iterations--) {
|
||||||
|
fn();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
elapsed = end - start;
|
||||||
|
return {
|
||||||
|
count: count,
|
||||||
|
total: elapsed,
|
||||||
|
time: elapsed / count,
|
||||||
|
name: fn.name,
|
||||||
|
msg: '' + pad(elapsed / count, 3)
|
||||||
|
+ ' ms [ ' + pad(1 / elapsed * count * 1000, 0) + ' ops/sec ] '
|
||||||
|
+ '(' + elapsed + ' ms/' + count + ')'
|
||||||
|
};
|
||||||
|
|
||||||
return duration;
|
}
|
||||||
}
|
|
||||||
|
function perf() {
|
||||||
|
var log = [],
|
||||||
|
summary = [],
|
||||||
|
i,
|
||||||
|
baseline,
|
||||||
|
pad = angularFilter.number;
|
||||||
|
|
||||||
|
for (i = 0; i < arguments.length; i++) {
|
||||||
|
var fn = arguments[i];
|
||||||
|
var info = time(fn);
|
||||||
|
if (baseline === undefined) baseline = info.time;
|
||||||
|
summary.push(info.name + ': ' + pad(baseline / info.time, 2) + ' X');
|
||||||
|
log.push('\n ' + info.name + ': ' + info.msg);
|
||||||
|
}
|
||||||
|
log.unshift(summary.join(' - '));
|
||||||
|
dump(log.join(' '));
|
||||||
|
}
|
||||||
|
|
|
||||||
4
test-reset.sh
Executable file
4
test-reset.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
tests=$1
|
||||||
|
|
||||||
|
java -jar lib/jstestdriver/JsTestDriver.jar --tests all --reset
|
||||||
Loading…
Reference in a new issue