From 11d94ab6531c9aca6383f6eb8f23d182ea003d75 Mon Sep 17 00:00:00 2001 From: David Rodenas Pico Date: Mon, 10 Oct 2016 17:46:42 +0200 Subject: [PATCH] chore(benchpress): add a ngClass benchmark --- benchmarks/ng-class-bp/app.js | 108 ++++++++++++++++++ benchmarks/ng-class-bp/bp.conf.js | 15 +++ benchmarks/ng-class-bp/main.html | 177 ++++++++++++++++++++++++++++++ 3 files changed, 300 insertions(+) create mode 100644 benchmarks/ng-class-bp/app.js create mode 100644 benchmarks/ng-class-bp/bp.conf.js create mode 100644 benchmarks/ng-class-bp/main.html diff --git a/benchmarks/ng-class-bp/app.js b/benchmarks/ng-class-bp/app.js new file mode 100644 index 000000000000..fba4279d7947 --- /dev/null +++ b/benchmarks/ng-class-bp/app.js @@ -0,0 +1,108 @@ +'use strict'; + +var app = angular.module('ngClassBenchmark', []); + +app.controller('DataController', function DataController($scope) { + + this.init = function() { + this.numberOfTodos = 1000; + this.implementation = 'tableOptimized'; + this.completedPeriodicity = 3; + this.importantPeriodicity = 13; + this.urgentPeriodicity = 29; + + this.createTodos(100); + this.setTodosValuesWithSeed(0); + }; + + this.clearTodos = function() { + this.todos = null; + }; + + this.createTodos = function(count) { + var i; + this.todos = []; + for (i = 0; i < count; i++) { + this.todos.push({ + id: i + 1, + completed: false, + important: false, + urgent: false + }); + } + }; + + this.setTodosValuesWithSeed = function(offset) { + var i, todo; + for (i = 0; i < this.todos.length; i++) { + todo = this.todos[i]; + todo.completed = 0 === (i + offset) % this.completedPeriodicity; + todo.important = 0 === (i + offset) % this.importantPeriodicity; + todo.urgent = 0 === (i + offset) % this.urgentPeriodicity; + } + }; + + this.init(); + + + benchmarkSteps.push({ + name: 'setup', + fn: function() { + $scope.$apply(); + this.clearTodos(); + this.createTodos(this.numberOfTodos); + }.bind(this) + }); + + benchmarkSteps.push({ + name: 'create', + fn: function() { + // initialize data for first time that will construct the DOM + this.setTodosValuesWithSeed(0); + $scope.$apply(); + }.bind(this) + }); + + benchmarkSteps.push({ + name: '$apply', + fn: function() { + $scope.$apply(); + } + }); + + benchmarkSteps.push({ + name: 'update', + fn: function() { + // move everything but completed + this.setTodosValuesWithSeed(3); + $scope.$apply(); + }.bind(this) + }); + + benchmarkSteps.push({ + name: 'unclass', + fn: function() { + // remove all classes + this.setTodosValuesWithSeed(NaN); + $scope.$apply(); + }.bind(this) + }); + + benchmarkSteps.push({ + name: 'class', + fn: function() { + // add all classes as the initial state + this.setTodosValuesWithSeed(0); + $scope.$apply(); + }.bind(this) + }); + + benchmarkSteps.push({ + name: 'destroy', + fn: function() { + this.clearTodos(); + $scope.$apply(); + }.bind(this) + }); + +}); diff --git a/benchmarks/ng-class-bp/bp.conf.js b/benchmarks/ng-class-bp/bp.conf.js new file mode 100644 index 000000000000..f506db816a97 --- /dev/null +++ b/benchmarks/ng-class-bp/bp.conf.js @@ -0,0 +1,15 @@ +/* eslint-env node */ + +'use strict'; + +module.exports = function(config) { + config.set({ + scripts: [{ + id: 'angular', + src: '/build/angular.js' + }, + { + src: 'app.js' + }] + }); +}; diff --git a/benchmarks/ng-class-bp/main.html b/benchmarks/ng-class-bp/main.html new file mode 100644 index 000000000000..e0d41749b9ea --- /dev/null +++ b/benchmarks/ng-class-bp/main.html @@ -0,0 +1,177 @@ + +
+
+
+ +
+

Parameters

+ +
+

+
+ +

+ +
+

+
+

+ +
+
+ +
+
+ +
+
+ +
+
+ +
+

+
+ +
+

Example

+
+ + + + + + + + + + + + + + + + + + +
todo #idcompleted?urgent?important?
#{{todo.id}}{{todo.completed}}{{todo.urgent}}{{todo.important}}
+ + + + + + + + + + + + + + + + + + +
todo #idcompleted?urgent?important?
#{{todo.id}}{{todo.completed}}{{todo.urgent}}{{todo.important}}
+ +
    +
  • #{{todo.id}}
  • +
+ +
+
+

Information

+
+
The title is green because there are todos...
+
+ +
+
+

Information

+
+
The title is green because there are todos...
+
+
+ +
+
+
+