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

Commit 91cafff

Browse files
petebacondarwinNarretz
authored andcommitted
chore(benchpress): add benchmarks for select with ngValue
1 parent 759fdcd commit 91cafff

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

benchmarks/select-ng-value-bp/app.js

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"use strict";
2+
3+
/* globals angular, benchmarkSteps */
4+
5+
var app = angular.module('selectBenchmark', []);
6+
7+
app.config(function($compileProvider) {
8+
if ($compileProvider.debugInfoEnabled) {
9+
$compileProvider.debugInfoEnabled(false);
10+
}
11+
});
12+
13+
14+
15+
app.controller('DataController', function($scope, $element) {
16+
$scope.groups = [];
17+
$scope.count = 10000;
18+
19+
function changeOptions() {
20+
$scope.groups = [];
21+
var i = 0;
22+
var group;
23+
while(i < $scope.count) {
24+
if (i % 100 === 0) {
25+
group = {
26+
name: 'group-' + $scope.groups.length,
27+
items: []
28+
};
29+
$scope.groups.push(group);
30+
}
31+
group.items.push({
32+
id: i,
33+
label: 'item-' + i
34+
});
35+
i++;
36+
}
37+
}
38+
39+
var selectElement = $element.find('select');
40+
console.log(selectElement);
41+
42+
43+
benchmarkSteps.push({
44+
name: 'add-options',
45+
fn: function() {
46+
$scope.$apply(function() {
47+
$scope.count = 10000;
48+
changeOptions();
49+
});
50+
}
51+
});
52+
53+
benchmarkSteps.push({
54+
name: 'set-model-1',
55+
fn: function() {
56+
$scope.$apply(function() {
57+
$scope.x = $scope.groups[10].items[0];
58+
});
59+
}
60+
});
61+
62+
benchmarkSteps.push({
63+
name: 'set-model-2',
64+
fn: function() {
65+
$scope.$apply(function() {
66+
$scope.x = $scope.groups[0].items[10];
67+
});
68+
}
69+
});
70+
71+
benchmarkSteps.push({
72+
name: 'remove-options',
73+
fn: function() {
74+
$scope.count = 100;
75+
changeOptions();
76+
}
77+
});
78+
79+
benchmarkSteps.push({
80+
name: 'add-options',
81+
fn: function() {
82+
$scope.$apply(function() {
83+
$scope.count = 10000;
84+
changeOptions();
85+
});
86+
}
87+
});
88+
89+
benchmarkSteps.push({
90+
name: 'set-view-1',
91+
fn: function() {
92+
selectElement.val('2000');
93+
selectElement.triggerHandler('change');
94+
}
95+
});
96+
97+
benchmarkSteps.push({
98+
name: 'set-view-2',
99+
fn: function() {
100+
selectElement.val('1000');
101+
selectElement.triggerHandler('change');
102+
}
103+
});
104+
});
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = function(config) {
2+
config.set({
3+
scripts: [ {
4+
id: 'angular',
5+
src: '/build/angular.js'
6+
},
7+
{
8+
src: 'app.js',
9+
}]
10+
});
11+
};
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div ng-app="selectBenchmark" ng-cloak>
2+
<div ng-controller="DataController">
3+
<div class="container-fluid">
4+
<p>
5+
Tests the execution of a select with ngRepeat'ed options with ngValue for rendering during model
6+
and option updates.
7+
</p>
8+
<select ng-model="x">
9+
<optgroup ng-repeat="g in groups track by g.name" label="{{g.name}}">
10+
<option ng-repeat="a in g.items track by a.id" ng-value="a">{{a.label}}</option>
11+
</optgroup>
12+
</select>
13+
</div>
14+
</div>
15+
</div>

0 commit comments

Comments
 (0)