WP Event/Action system performance test
WP Event/Action system performance test
by skibulk
JavaScript
// WP Event/Action system performance test
console.clear();
function sayHello(){
if(1 == 2 || 1 == 3) {
console.log("hello");
}
}
var hello = new Event("hello");
// No matter how many times you register a callback, it will only be called once
for(var i = 0; i < 10; i++){
window.addEventListener("hello", sayHello);
}
window.dispatchEvent(hello);
console.log("TEST 2 SRART " + Date.now() / 1000);
var handlers = [];
for(var i = 0; i < 10000; i++){
handlers.push(sayHello);
}
for(var i = 0; i < handlers.length; i++){
handlers[i]();
}
console.log("TEST 2 STOP " + Date.now() / 1000 );