Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1229334

Browse files
committed
perf(benchpress): add benchpress node module and port over large table test
1 parent 77a1acc commit 1229334

File tree

5 files changed

+252
-1
lines changed

5 files changed

+252
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/build/
2+
/benchpress-build/
23
.DS_Store
34
gen_docs.disable
45
test.disable

benchmarks/largetable-bp/app.js

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
var app = angular.module('largetableBenchmark', []);
2+
3+
app.filter('noop', function() {
4+
return function(input) {
5+
return input;
6+
};
7+
});
8+
9+
app.controller('DataController', function($scope, $rootScope) {
10+
var totalRows = 1000;
11+
var totalColumns = 20;
12+
13+
var data = $scope.data = [];
14+
$scope.digestDuration = '?';
15+
$scope.numberOfBindings = totalRows*totalColumns*2 + totalRows + 1;
16+
$scope.numberOfWatches = '?';
17+
18+
function iGetter() { return this.i; }
19+
function jGetter() { return this.j; }
20+
21+
for (var i=0; i<totalRows; i++) {
22+
data[i] = [];
23+
for (var j=0; j<totalColumns; j++) {
24+
data[i][j] = {
25+
i: i, j: j,
26+
iFn: iGetter,
27+
jFn: jGetter
28+
};
29+
}
30+
}
31+
32+
var previousType;
33+
34+
benchmarkSteps.push({
35+
name: 'destroy',
36+
fn: function() {
37+
$scope.$apply(function() {
38+
previousType = $scope.benchmarkType;
39+
$scope.benchmarkType = 'none';
40+
});
41+
}
42+
});
43+
44+
benchmarkSteps.push({
45+
name: 'create',
46+
fn: function() {
47+
$scope.$apply(function() {
48+
$scope.benchmarkType = previousType;
49+
});
50+
}
51+
});
52+
53+
benchmarkSteps.push({
54+
name: '$apply',
55+
fn: function() {
56+
$rootScope.$apply();
57+
}
58+
});
59+
});
60+
61+
var fn = function() { return 'x'};
62+
63+
64+
app.directive('baselineBindingTable', function() {
65+
return {
66+
restrict: 'E',
67+
link: function ($scope, $element) {
68+
var i, j, row, cell, comment;
69+
var template = document.createElement('span');
70+
template.setAttribute('ng-repeat', 'foo in foos');
71+
template.classList.add('ng-scope');
72+
template.appendChild(document.createElement('span'));
73+
template.appendChild(document.createTextNode(':'));
74+
template.appendChild(document.createElement('span'));
75+
template.appendChild(document.createTextNode('|'));
76+
77+
for (i = 0; i < 1000; i++) {
78+
row = document.createElement('div');
79+
$element[0].appendChild(row);
80+
for (j = 0; j < 20; j++) {
81+
cell = template.cloneNode(true);
82+
row.appendChild(cell);
83+
cell.childNodes[0].textContent = i;
84+
cell.childNodes[2].textContent = j;
85+
cell.ng3992 = 'xxx';
86+
comment = document.createComment('ngRepeat end: bar in foo');
87+
row.appendChild(comment);
88+
}
89+
90+
comment = document.createComment('ngRepeat end: foo in foos');
91+
$element[0].appendChild(comment);
92+
}
93+
}
94+
};
95+
});
96+
97+
98+
app.directive('baselineInterpolationTable', function() {
99+
return {
100+
restrict: 'E',
101+
link: function ($scope, $element) {
102+
var i, j, row, cell, comment;
103+
var template = document.createElement('span');
104+
template.setAttribute('ng-repeat', 'foo in foos');
105+
template.classList.add('ng-scope');
106+
107+
for (i = 0; i < 1000; i++) {
108+
row = document.createElement('div');
109+
$element[0].appendChild(row);
110+
for (j = 0; j < 20; j++) {
111+
cell = template.cloneNode(true);
112+
row.appendChild(cell);
113+
cell.textContent = '' + i + ':' + j + '|';
114+
cell.ng3992 = 'xxx';
115+
comment = document.createComment('ngRepeat end: bar in foo');
116+
row.appendChild(comment);
117+
}
118+
119+
comment = document.createComment('ngRepeat end: foo in foos');
120+
$element[0].appendChild(comment);
121+
}
122+
}
123+
};
124+
});
125+
126+
127+
128+
/*
129+
130+
the fastest
131+
240/44
132+
133+
app.directive('baselineTable', function() {
134+
return function($scope, $element) {
135+
var i, j, row, cell;
136+
137+
for (i = 0; i < 1000; i++) {
138+
row = document.createElement('div');
139+
for (j = 0; j < 20; j++) {
140+
cell = document.createElement('span');
141+
cell.textContent = '' + i + ':' + j;
142+
row.appendChild(cell);
143+
}
144+
$element[0].appendChild(row);
145+
}
146+
};
147+
});
148+
149+
*/
150+
151+
/*
152+
with comments and expando
153+
232/90
154+
155+
app.directive('baselineTable', function() {
156+
return function($scope, $element) {
157+
var i, j, row, cell, comment;
158+
159+
for (i = 0; i < 1000; i++) {
160+
row = document.createElement('div');
161+
$element[0].appendChild(row);
162+
for (j = 0; j < 20; j++) {
163+
cell = document.createElement('span');
164+
row.appendChild(cell);
165+
cell.textContent = '' + i + ':' + j;
166+
cell.ng3992 = 'xxx';
167+
comment = document.createComment('ngRepeat end: bar in foo');
168+
row.appendChild(comment);
169+
}
170+
171+
comment = document.createComment('ngRepeat end: foo in foos');
172+
$element[0].appendChild(comment);
173+
}
174+
};
175+
});
176+
177+
*/

benchmarks/largetable-bp/bp.conf.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function(config) {
2+
config.set({
3+
scripts: [{
4+
id: 'angular',
5+
src: '/build/angular.js'
6+
},{
7+
src: 'app.js',
8+
}]
9+
});
10+
};

benchmarks/largetable-bp/main.html

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<div ng-app="largetableBenchmark">
2+
<div ng-controller="DataController">
3+
<div class="container-fluid">
4+
<p>
5+
Large table rendered with AngularJS
6+
</p>
7+
8+
<div>none: <input type=radio ng-model="benchmarkType" value="none"></div>
9+
<div>baseline binding: <input type=radio ng-model="benchmarkType" value="baselineBinding"></div>
10+
<div>baseline interpolation: <input type=radio ng-model="benchmarkType" value="baselineInterpolation"></div>
11+
<div>ngBind: <input type=radio ng-model="benchmarkType" value="ngBind"></div>
12+
<div>interpolation: <input type=radio ng-model="benchmarkType" value="interpolation"></div>
13+
<div>ngBind + fnInvocation: <input type=radio ng-model="benchmarkType" value="ngBindFn"></div>
14+
<div>interpolation + fnInvocation: <input type=radio ng-model="benchmarkType" value="interpolationFn"></div>
15+
<div>ngBind + filter: <input type=radio ng-model="benchmarkType" value="ngBindFilter"></div>
16+
<div>ngBind + filter: <input type=radio ng-model="benchmarkType" value="interpolationFilter"></div>
17+
18+
<ng-switch on="benchmarkType">
19+
<baseline-binding-table ng-switch-when="baselineBinding">
20+
</baseline-binding-table>
21+
<baseline-interpolation-table ng-switch-when="baselineInterpolation">
22+
</baseline-interpolation-table>
23+
<div ng-switch-when="ngBind">
24+
<h2>baseline binding</h2>
25+
<div ng-repeat="row in data">
26+
<span ng-repeat="column in row"><span ng-bind="column.i"></span>:<span ng-bind="column.j"></span>|</span>
27+
</div>
28+
</div>
29+
<div ng-switch-when="interpolation">
30+
<h2>baseline interpolation</h2>
31+
<div ng-repeat="row in data">
32+
<span ng-repeat="column in row">{{column.i}}:{{column.j}}|</span>
33+
</div>
34+
</div>
35+
<div ng-switch-when="ngBindFn">
36+
<h2>bindings with functions</h2>
37+
<div ng-repeat="row in data">
38+
<span ng-repeat="column in row"><span ng-bind="column.iFn()"></span>:<span ng-bind="column.jFn()"></span>|</span>
39+
</div>
40+
</div>
41+
<div ng-switch-when="interpolationFn">
42+
<h2>interpolation with functions</h2>
43+
<div ng-repeat="row in data">
44+
<span ng-repeat="column in row">{{column.iFn()}}:{{column.jFn()}}|</span>
45+
</div>
46+
</div>
47+
<div ng-switch-when="ngBindFilter">
48+
<h2>bindings with filter</h2>
49+
<div ng-repeat="row in data">
50+
<span ng-repeat="column in row"><span ng-bind="column.i | noop"></span>:<span ng-bind="column.j | noop"></span>|</span>
51+
</div>
52+
</div>
53+
<div ng-switch-when="interpolationFilter">
54+
<h2>interpolation with filter</h2>
55+
<div ng-repeat="row in data">
56+
<span ng-repeat="column in row">{{column.i | noop}}:{{column.j | noop}}|</span>
57+
</div>
58+
</div>
59+
</ng-switch>
60+
</div>
61+
</div>
62+
</div>

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"node-html-encoder": "0.0.2",
5555
"sorted-object": "^1.0.0",
5656
"qq": "^0.3.5",
57-
"benchmark": "1.x.x"
57+
"benchmark": "1.x.x",
58+
"angular-benchpress": "0.0.2"
5859
},
5960
"licenses": [
6061
{

0 commit comments

Comments
 (0)