Benchmark name When Created
Observables: loops versus EventTarget (3 listeners)

When the “observable” pattern is implemented in JavaScript, it's practically always done using a loop over callbacks. One problem with this approach is that an exception in one handler will crash the entire loop. You can work around this by wrapping the invocation in a try/catch block, but in doing so, you silently swallow the error. The browser provides an event dispatcher for DOM elements that runs each handler in a separate execution context, providing a better failure mode for independent listeners. `EventTarget` is an interface, so you can't directly instantiate one. But you can hijack the `EventTarget` implementation from a dummy object. This test compares multi-listener dispatches using loops and the built-in `EventTarget`. My expectation is that the native mechanism will carry some overhead, partly because of the bespoke execution context, and partly because of the extra properties instantiated on each `CustomEvent` instance. This method also has to look up events by their (string) names, rather than using direct object reference. See http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/

2 years ago
Observables: loops versus EventTarget

When the “observable” pattern is implemented in JavaScript, it's practically always done using a loop over callbacks. One problem with this approach is that an exception in one handler will crash the entire loop. You can work around this by wrapping the invocation in a try/catch block, but in doing so, you silently swallow the error. The browser provides an event dispatcher for DOM elements that runs each handler in a separate execution context, providing a better failure mode for independent listeners. `EventTarget` is an interface, so you can't directly instantiate one. But you can hijack the `EventTarget` implementation from a dummy object. This test compares multi-listener dispatches using loops and the built-in `EventTarget`. My expectation is that the native mechanism will carry some overhead, partly because of the bespoke execution context, and partly because of the extra properties instantiated on each `CustomEvent` instance. This method also has to look up events by their (string) names, rather than using direct object reference. See http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/

2 years ago
innerHTML vs removeChild 2 years ago
Array .push() vs .unshift() 2 years ago
Array .push() vs .unshift() 2 years ago
Object Composition vs Instantiation 2 years ago
Array Remove vs String Replace 2 years ago
Try-Catch Loop 2 years ago
Try-Catch Loop 2 years ago
Try-Catch Loop 2 years ago
Arrays vs Objects 2 years ago
Local scope vs outer scope variables (fixed)

Cache variable in the function scope

2 years ago
Local scope vs outer scope variables

Cache variable in the function scope

2 years ago
Which equals operator (== vs ===) is faster?

Is there a performance benefit to replacing == with ===?

2 years ago
Demo benchmark as guest user 2 years ago
regex test

Test

2 years ago
regex test

Test

2 years ago
Dummy Test 2 years ago
forEach vs for vs Query each vs for of

with <link>

2 years ago
forEach vs for vs Query each

with <link>

2 years ago
forEach vs for vs Query each

with <link>

2 years ago
forEach vs jQuery each

with <link>

2 years ago
Array filter vs. for loop - with for in 2

This version declares i once before

2 years ago
Array filter vs. for loop - with for in 2 years ago
Array filter vs. for loop (fixed really really) 2 years ago

 Create benchmark Your benchmarks