aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2011-03-19 09:57:18 +0530
committerMisko Hevery2011-06-08 13:49:10 -0700
commitfab4ada3c849becede839530d812748064654bd6 (patch)
tree395563f7c834da1fea993b2693a071e4e4a88947
parentd6eba8f39ff78061a4f9bfaefa1bb1f592f7e0ef (diff)
downloadangular.js-fab4ada3c849becede839530d812748064654bd6.tar.bz2
Created a performance test harness and reporter
-rw-r--r--.externalToolBuilders/JSTD_perf.launch10
-rw-r--r--.project10
-rw-r--r--jsTestDriver-coverage.conf2
-rw-r--r--jsTestDriver-jquery.conf2
-rw-r--r--jsTestDriver-perf.conf11
-rw-r--r--perf/jsonPerfSpec.js34
-rw-r--r--perf/testUtils.js73
-rwxr-xr-xtest-reset.sh4
8 files changed, 103 insertions, 43 deletions
diff --git a/.externalToolBuilders/JSTD_perf.launch b/.externalToolBuilders/JSTD_perf.launch
new file mode 100644
index 00000000..abbde2cd
--- /dev/null
+++ b/.externalToolBuilders/JSTD_perf.launch
@@ -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:&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;}"/>
+<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>
diff --git a/.project b/.project
index a5cd3ee0..0577303a 100644
--- a/.project
+++ b/.project
@@ -30,6 +30,16 @@
</dictionary>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
+ <triggers>auto,full,incremental,</triggers>
+ <arguments>
+ <dictionary>
+ <key>LaunchConfigHandle</key>
+ <value>&lt;project&gt;/.externalToolBuilders/JSTD_perf.launch</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
diff --git a/jsTestDriver-coverage.conf b/jsTestDriver-coverage.conf
index b8989811..2021e740 100644
--- a/jsTestDriver-coverage.conf
+++ b/jsTestDriver-coverage.conf
@@ -24,8 +24,6 @@ load:
exclude:
- test/jquery_alias.js
- - src/angular.prefix
- - src/angular.suffix
- src/angular-bootstrap.js
- src/scenario/angular-bootstrap.js
- src/AngularPublic.js
diff --git a/jsTestDriver-jquery.conf b/jsTestDriver-jquery.conf
index 9ae54022..3926378f 100644
--- a/jsTestDriver-jquery.conf
+++ b/jsTestDriver-jquery.conf
@@ -23,8 +23,6 @@ load:
- example/personalLog/test/*.js
exclude:
- - src/angular.prefix
- - src/angular.suffix
- src/angular-bootstrap.js
- src/AngularPublic.js
- src/scenario/angular-bootstrap.js
diff --git a/jsTestDriver-perf.conf b/jsTestDriver-perf.conf
index 8b0518b3..bf400847 100644
--- a/jsTestDriver-perf.conf
+++ b/jsTestDriver-perf.conf
@@ -3,11 +3,16 @@ 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
+ - src/Angular.js
+ - src/JSON.js
+ - src/*.js
+ - src/service/*.js
+ - src/angular-mocks.js
- perf/data/*.js
- perf/testUtils.js
- perf/*.js
exclude:
+ - src/angular-bootstrap.js
+ - src/scenario/angular-bootstrap.js
+ - src/AngularPublic.js
diff --git a/perf/jsonPerfSpec.js b/perf/jsonPerfSpec.js
index 01a489e2..edc4b6b2 100644
--- a/perf/jsonPerfSpec.js
+++ b/perf/jsonPerfSpec.js
@@ -1,28 +1,16 @@
describe('json', function() {
it('angular parser', function() {
- var duration = time(function() {
- expect(angular.fromJson(largeJsonString)).toBeTruthy();
- }, 1);
-
- dump(duration/1 + ' ms per iteration');
- });
-
-
- it('angular delegating to native parser', function() {
- 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');
+ perf(
+ function angular() {
+ fromJson(largeJsonString);
+ },
+ function nativeDelegate() {
+ fromJson(largeJsonString, true);
+ },
+ function nativeJSON() {
+ JSON.parse(largeJsonString);
+ }
+ );
});
});
diff --git a/perf/testUtils.js b/perf/testUtils.js
index ca016c31..2fc4f8a2 100644
--- a/perf/testUtils.js
+++ b/perf/testUtils.js
@@ -1,20 +1,67 @@
if (window.jstestdriver) {
jstd = jstestdriver;
- dump = angular.bind(jstd.console, jstd.console.log);
+ dump = bind(jstd.console, jstd.console.log);
}
-function time(fn, times) {
- times = times || 1;
+function time(fn) {
+ var count = 1,
+ targetTime = 500,
+ start = new Date().getTime(),
+ stop = start + targetTime,
+ elapsed,
+ end,
+ iterations,
+ pad = angularFilter.number;
- var i,
- start,
- duration = 0;
-
- for (i=0; i<times; i++) {
- start = Date.now();
- fn();
- duration += Date.now() - start;
+ // do one iteration to guess how long it will take
+ fn();
+ while((end=new Date().getTime()) < stop ){
+ // how much time has elapsed since we started the test
+ elapsed = (end-start) || 1;
+ // guess how many more iterations we need before we reach
+ // the time limit. We do this so that we spend most of our
+ // 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;
-} \ No newline at end of file
+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(' '));
+}
diff --git a/test-reset.sh b/test-reset.sh
new file mode 100755
index 00000000..41822fd4
--- /dev/null
+++ b/test-reset.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+tests=$1
+
+java -jar lib/jstestdriver/JsTestDriver.jar --tests all --reset