$rootScope.emit() vs $rootScope.$broadcast() (v92)

Revision 92 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>

<script>
angular
    .module("testApp",[])
    .controller("itemController",function($rootScope, $scope) {
       window.$scopeItem = $scope;
    })
    .controller("testController",function($rootScope, $scope) {

        window.$rootScope = $rootScope;

 $scope.testVal = '';
        window.$scope = $scope;

        var items = $scope.items = [];

        for (i=0;i<3;i++){
            items.push({
                number: i,
                text: 'some text'
            })
        }

    });
</script>

<div ng-app="testApp">
    <div ng-controller="testController">
        <ul>
            <li ng-repeat="item in items" ng-bind="item.number" ng-controller="itemController">
            </li>
        </ul>
    </div>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
$watch
window.$scope.$watch('testVal', function() { });
ready
$emit
var destroyFooHappened = window.$rootScope.$on('fooHappened');

window.$scopeItem.$on('$destroy', function() {
			destroyFooHappened ();
});

window.$rootScope.$emit('fooHappened');
ready
$broadcast
window.$scopeItem.$on('fooHappened', function() {return;});

window.$scope.$broadcast('fooHappened');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.