Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Parallel execution
(version: 0)
Comparing performance of:
Promise all vs Array
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const asyncBuilder = (t) => async () => setTimeout(() => t, t) const a10s = asyncBuilder(100);
Tests:
Promise all
async () => await Promise.all([a10s(), a10s()])()
Array
async () => [await a10s(), await a10s()]()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Promise all
Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Promise all
227995776.0 Ops/sec
Array
221708032.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the explanation into manageable parts to help software engineers understand the benchmark. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmark, which is a small program designed to measure the performance of specific code snippets. In this case, the benchmark is named "Parallel execution" and its description is null, indicating that no detailed explanation is required. The script preparation code defines two constants: * `asyncBuilder` is a function that takes a time value `t` as input and returns an asynchronous function that waits for `t` milliseconds before executing another function with the same name. This creates a closure, where the inner function captures the outer function's scope. * `a10s` is an alias for `asyncBuilder(100)`, which means it will wait for 100 milliseconds before executing. **Comparison Options** The benchmark compares two approaches: 1. **Array**: The script uses the syntax `[...].await` to execute the `a10s()` function twice in parallel. 2. **Promise all**: The script uses `Promise.all([a10s(), a10s()])` to execute both `a10s()` functions in parallel. **Pros and Cons** * **Array approach**: + Pros: This method is straightforward, easy to understand, and does not require additional libraries. + Cons: It may not be the most efficient way to run two independent asynchronous operations in parallel. * **Promise all approach**: + Pros: This method allows for better control over the execution order of multiple promises and can be more efficient than using an array. + Cons: It requires a good understanding of Promises and may introduce additional overhead. **Library** The benchmark does not use any external libraries. However, it relies on the built-in JavaScript features, such as `setTimeout`, `Promise.all`, and the `await` keyword (introduced in ECMAScript 2017). **Special JS feature/syntax** The benchmark uses the following special syntax: * `async/await`: This is a pair of keywords introduced in ECMAScript 2015 that allows writing asynchronous code that looks like synchronous code. **Benchmark Preparation Code** The script preparation code defines two constants: `asyncBuilder` and `a10s`. The latter is an alias for the former, which creates a closure. This approach ensures that both functions have access to the same scope variables. **Individual Test Cases** Each test case represents a single benchmark iteration. In this case, there are only two test cases: 1. **Promise all**: This test case executes the `a10s()` function twice in parallel using `Promise.all`. 2. **Array**: This test case uses an array syntax to execute the same functions in parallel. **Latest Benchmark Result** The benchmark result shows that, on a desktop platform with Firefox 83 browser and Windows operating system, running both approaches resulted in different execution rates: * **Promise all**: Executed approximately 599 million times per second. * **Array**: Executed approximately 650 million times per second. This suggests that the `Array` approach might be slightly faster than using `Promise.all`. However, it's essential to note that this result depends on various factors, including the specific hardware and software configuration used for benchmarking.
Related benchmarks:
Parallel execution 2
async for vs promise all (setTimeout version)
async for vs promise.all /w delay
Promisify test
Comments
Confirm delete:
Do you really want to delete benchmark?