((next) => {next()})(() => {});
new Promise((resolve) => { resolve(true)});
(async() => { await true; })();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Callback | |
Promise | |
Async |
Test name | Executions per second |
---|---|
Callback | 236888464.0 Ops/sec |
Promise | 17977460.0 Ops/sec |
Async | 8361424.0 Ops/sec |
Let's break down the benchmark and explain what's being tested.
What is being tested?
The benchmark compares three different approaches for handling asynchronous operations in JavaScript:
Options compared
The benchmark compares the performance of each approach:
await
keyword is used to wait for the resolution.await
keyword is used to wait for the resolution of the promises.Pros and Cons
Here's a brief overview of each approach:
Library and special JS feature
There is no specific library being used in this benchmark, other than the built-in JavaScript features mentioned above.
Special JS feature
The await
keyword is a special JavaScript feature introduced in modern JavaScript versions (ES6+). It allows for asynchronous programming with a synchronous API, making it easier to write and read code that handles asynchronous operations.
Other alternatives
If async/await is not supported by the browser, developers can use callbacks or promises as an alternative. However, if they want to take advantage of the concise syntax and expressive nature of async/await, they may need to opt for a different approach, such as using Web Workers for parallel execution.
In summary, the benchmark compares three approaches for handling asynchronous operations in JavaScript: callbacks, promises, and async/await. Each approach has its pros and cons, and the choice depends on the specific use case, performance requirements, and personal preference.