Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
callbacks vs promises vs async/awaits
(version: 0)
Comparing performance of:
callbacks vs promises vs async/awaits
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
callbacks
((cb) => {cb()})(() => {});
promises
(()=>Promise.resolve())();
async/awaits
(async() => { await true; })();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
callbacks
promises
async/awaits
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
callbacks
84077792.0 Ops/sec
promises
46208680.0 Ops/sec
async/awaits
444807.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **What's being compared:** The benchmark is comparing three different approaches to handling asynchronous operations: 1. **Callbacks**: This approach uses a callback function to execute another function after some operation is complete. In the benchmark, `((cb) => {cb()})(() => {})` defines a callback function that immediately calls itself. 2. **Promises**: This approach uses promises to handle asynchronous operations. A promise is an object that represents a value that may not be available yet, but will be eventually. 3. **Async/Awaits**: This approach uses the `async` and `await` keywords to wait for the completion of an asynchronous operation. **Pros and Cons:** 1. **Callbacks**: * Pros: Simple, lightweight, and widely supported. * Cons: Can lead to callback hell (nested callbacks), making code harder to read and maintain. 2. **Promises**: * Pros: More readable than callbacks, supports chaining, and can be used with async/await. * Cons: Can be less efficient due to the overhead of promise creation and manipulation. 3. **Async/Awaits**: * Pros: Modern, concise, and easy to read. Allows for simpler code compared to promises. * Cons: Requires modern browsers or Node.js versions, which may not be compatible with older systems. **Library:** None explicitly mentioned in the benchmark definition, but `Promise` is a built-in JavaScript object used in the promise approach. **Special JS feature/syntax:** The async/await syntax requires support for modern browsers (including Firefox 129) or Node.js versions. The promises and callbacks approaches are more widely supported, but async/await is often considered more readable and concise. **Other alternatives:** 1. **Functions with a `then` method**: Instead of using a promise, you can use a callback function inside another function. 2. **Generators**: Can be used for asynchronous operations, providing an alternative to promises. 3. **Async/await with a polyfill**: If the browser or environment doesn't support async/await natively, you can use a polyfill to add support. Keep in mind that this benchmark focuses on comparing three specific approaches and might not cover all possible alternatives or edge cases.
Related benchmarks:
promise vs callback
just promise vs just callback
Promise vs async vs callbacks
Async vs Callback
Comments
Confirm delete:
Do you really want to delete benchmark?