forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(benchmark): add ngOptions benchmark
- Loading branch information
1 parent
1334b8c
commit 647d933
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"use strict"; | ||
|
||
/* globals angular, benchmarkSteps */ | ||
|
||
var app = angular.module('ngOptionsBenchmark', []); | ||
|
||
app.config(function($compileProvider) { | ||
if ($compileProvider.debugInfoEnabled) { | ||
$compileProvider.debugInfoEnabled(false); | ||
} | ||
}); | ||
|
||
|
||
|
||
app.controller('DataController', function($scope, $element) { | ||
$scope.items = []; | ||
$scope.count = 10000; | ||
|
||
function changeOptions() { | ||
$scope.items = []; | ||
for (var i = 0; i < $scope.count; ++i) { | ||
$scope.items.push({ | ||
id: i, | ||
label: 'item-' + i, | ||
group: 'group-' + i % 100 | ||
}); | ||
} | ||
} | ||
|
||
var selectElement = $element.find('select'); | ||
console.log(selectElement); | ||
|
||
|
||
benchmarkSteps.push({ | ||
name: 'add-options', | ||
fn: function() { | ||
$scope.$apply(function() { | ||
$scope.count = 10000; | ||
changeOptions(); | ||
}); | ||
} | ||
}); | ||
|
||
benchmarkSteps.push({ | ||
name: 'set-model-1', | ||
fn: function() { | ||
$scope.$apply(function() { | ||
$scope.x = $scope.items[1000]; | ||
}); | ||
} | ||
}); | ||
|
||
benchmarkSteps.push({ | ||
name: 'set-model-2', | ||
fn: function() { | ||
$scope.$apply(function() { | ||
$scope.x = $scope.items[10]; | ||
}); | ||
} | ||
}); | ||
|
||
benchmarkSteps.push({ | ||
name: 'remove-options', | ||
fn: function() { | ||
$scope.count = 100; | ||
changeOptions(); | ||
} | ||
}); | ||
|
||
benchmarkSteps.push({ | ||
name: 'add-options', | ||
fn: function() { | ||
$scope.$apply(function() { | ||
$scope.count = 10000; | ||
changeOptions(); | ||
}); | ||
} | ||
}); | ||
|
||
benchmarkSteps.push({ | ||
name: 'set-view-1', | ||
fn: function() { | ||
selectElement.val('2000'); | ||
selectElement.triggerHandler('change'); | ||
} | ||
}); | ||
|
||
benchmarkSteps.push({ | ||
name: 'set-view-2', | ||
fn: function() { | ||
selectElement.val('1000'); | ||
selectElement.triggerHandler('change'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = function(config) { | ||
config.set({ | ||
scripts: [ { | ||
id: 'angular', | ||
src: '/build/angular.js' | ||
}, | ||
{ | ||
src: 'app.js', | ||
}] | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div ng-app="ngOptionsBenchmark" ng-cloak> | ||
<div ng-controller="DataController"> | ||
<div class="container-fluid"> | ||
<p> | ||
Tests the execution of ng-options for rendering during model and option updates. | ||
</p> | ||
<select ng-model="x" ng-options="a as a.label group by a.group for a in items track by a.id"></select> | ||
</div> | ||
</div> | ||
</div> |