jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script>
angular
.module("testApp",[])
.controller("testController",['$rootScope', '$scope','SharingService', function($rootScope, $scope, shSrv) {
window.shSrv = shSrv;
window.$rootScope = $rootScope;
var items = $scope.items = [];
for (i=0;i<100;i++){
items.push({
number: i,
text: 'some text'
})
}
}]).controller("liController", ['$rootScope','$scope','SharingService', function($rootScope, $scope, shSrv){
$scope.$on("fooHappened", function() {});
shSrv.subscribe("CustomerChange", function(){});
}]).factory('SharingService', ['$timeout', '$filter', '$log', function($timeout, $filter, $log) {
// Mapa de eventos subscritos
var eventMap = {};
var SharingService = {};
// Propaga los datos en la ngApp actual
SharingService.publish = function(eventName, data){
if(eventMap[eventName]) {
var scopes = eventMap[eventName];
for(var i=0,l=scopes.length; i<l; i++) {
scopes[i].evFn.apply(scopes[i], [data]);
}
}
};
// Realiza la subscripcion a un determinado event
SharingService.subscribe = function(scope, eventName, fn) {
if(!eventMap[eventName]) {
eventMap[eventName] = [];
}
var idSc = scope.$id || scope.id;
eventMap[eventName].push({sc:idSc, evFn: fn});
// Evento para eliminar el subscribe en caso de que se elimine el scope que hemos asociado
scope.$on("$destroy", function() {
SharingService.unsubscribe(scope);
});
};
// Cancela la subcripcion de un evento. Si eventName es nulo/undefined, cancela la subsripcion de todos los eventos del scope.
SharingService.unsubscribe = function(scope, eventName) {
var idSc = scope.$id || scope.id;
// Si no hemos pasado nombre de eventos, hacemos el unsubscribe de todos
if(eventName==undefined) {
for(var item in eventMap) {
if(eventMap.hasOwnProperty(item)){
eventName = item;
deleteEvents();
}
}
} else {
if(eventMap[eventName]) {
deleteEvents();
}
}
function deleteEvents() {
var scopes = angular.copy(eventMap[eventName]);
for(var i=0,l=scopes.length; i<l; i++) {
if(scopes[i].sc === idSc) {
eventMap[eventName].splice(i,1);
}
}
}
};
return SharingService;
}]);;
</script>
<div ng-app="testApp">
<div ng-controller="testController">
<ul>
<li ng-repeat="item in items" >
<div ng-controller="liController" ng-bind="item.number"></div>
</li>
</ul>
</div>
</div>
Ready to run.
Test | Ops/sec | |
---|---|---|
$broadcast |
| ready |
$emit |
| ready |
SharingService |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.