From 10b09dfc8a05373ba600dd4ed1e80c401cadeed3 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Thu, 4 Sep 2014 22:11:30 -0700 Subject: [PATCH] test($parse): adding benchmark for execution of $parse()ed expressions Part of #8901 --- benchmarks/parsed-expressions-bp/app.js | 86 +++++++++ benchmarks/parsed-expressions-bp/bp.conf.js | 11 ++ benchmarks/parsed-expressions-bp/main.html | 190 ++++++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100755 benchmarks/parsed-expressions-bp/app.js create mode 100755 benchmarks/parsed-expressions-bp/bp.conf.js create mode 100755 benchmarks/parsed-expressions-bp/main.html diff --git a/benchmarks/parsed-expressions-bp/app.js b/benchmarks/parsed-expressions-bp/app.js new file mode 100755 index 00000000..e8206fd9 --- /dev/null +++ b/benchmarks/parsed-expressions-bp/app.js @@ -0,0 +1,86 @@ +var app = angular.module('parsedExpressionBenchmark', []); + +app.config(function($compileProvider) { + if ($compileProvider.debugInfoEnabled) { + $compileProvider.debugInfoEnabled(false); + } +}); + +app.filter('noop', function() { + return function(input) { + return input; + }; +}); + +//Executes the specified expression as a watcher +app.directive('bmPeWatch', function() { + return { + restrict: 'A', + compile: function($element, $attrs) { + $element.text( $attrs.bmPeWatch ); + return function($scope, $element, $attrs) { + $scope.$watch($attrs.bmPeWatch, function(val) { + $element.text(val); + + }); + }; + } + }; +}); + +//Executes the specified expression as a watcher +//Adds a simple wrapper method to allow use of $watch instead of $watchCollection +app.directive('bmPeWatchLiteral', function($parse) { + function retZero() { + return 0; + } + + return { + restrict: 'A', + compile: function($element, $attrs) { + $element.text( $attrs.bmPeWatchLiteral ); + return function($scope, $element, $attrs) { + $scope.$watch( $parse($attrs.bmPeWatchLiteral, retZero) ); + }; + } + }; +}); + +app.controller('DataController', function($scope, $rootScope) { + var totalRows = 10000; + + var data = $scope.data = []; + + var star = '*'; + + $scope.func = function() { return star;}; + + for (var i=0; i +
+
+

+ Tests the execution of $parse()ed expressions. Each test tries to isolate specific expression types. Expressions should (probably) not be constant so they get evaluated per digest. +

+ +
    +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • +
+ + + +
    +
  • + + + + + + + + + + + +
  • + +
  • + + + + + + + + + + + + +
  • + +
  • + + + + + + + + + + + + + +
  • + +
  • + + + + + + + + + + + + + +
  • + +
  • + + + + + + + + + + + + +
  • + +
  • + + + + + + + + + + + + +
  • + +
  • + + + + + + +
  • + +
  • + + + + + + + + + + + + +
  • + + +
+
+
+