https://github.com/ivanhuay/micron-test-for-await
benchmark for await vs for + await
https://github.com/ivanhuay/micron-test-for-await
benchmark benchmarking javascript micron micron-runner node test
Last synced: 2 months ago
JSON representation
benchmark for await vs for + await
- Host: GitHub
- URL: https://github.com/ivanhuay/micron-test-for-await
- Owner: ivanhuay
- Created: 2019-06-28T17:24:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-28T17:27:06.000Z (almost 6 years ago)
- Last Synced: 2025-02-05T18:24:35.696Z (4 months ago)
- Topics: benchmark, benchmarking, javascript, micron, micron-runner, node, test
- Language: JavaScript
- Size: 34.2 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Micron Benchmark For await vs await
This is a benchmark to analize the performance between the two functions `for + await` vs `for-await`.## Motivation
In this benchmark we measure the performance variation using this two funcions:```javascript
for (var i = 0; i < limit; i++) {
let elm = await getResource();
}
```
vs
```javascript
data = {
[Symbol.asyncIterator]() {
return {
i: 0,
next() {
if (this.i < limit) {
this.i++;
return getResource()
.then((value)=>({value, done: false}));
}
return Promise.resolve({ done: true });
}
};
}
};
for await (let prom of data) {
}
````for await` looks simpler but you have to use an `AsyncIterator` that isn't simpler than using an array.
## Results
Both functions have similar performance but `for await` has more complexity because of the AsyncIterator. Only if we were using an async iterator previously the `for next` is better than a simple `for + await`.
[view results HERE](https://ivanhuay.github.io/micron-test-for-await/)
## run the test
```
git clone https://github.com/ivanhuay/micron-test-for-await.gitcd micron-test-for-await
npm i
npm run test
```after running that the results should be on the docs folder.