-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d036485
commit 42cae48
Showing
6 changed files
with
1,171 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
rules: { | ||
no-console: off, | ||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { ArrayIterator, range } from '../dist/asynciterator.js'; | ||
|
||
function noop() { | ||
// empty function to drain an iterator | ||
} | ||
|
||
async function perf(warmupIterator, iterator, description) { | ||
return new Promise(res => { | ||
const now = performance.now(); | ||
iterator.on('data', noop); | ||
iterator.on('end', () => { | ||
console.log(description, performance.now() - now); | ||
res(); | ||
}); | ||
}); | ||
} | ||
|
||
function run(iterator) { | ||
return new Promise(res => { | ||
iterator.on('data', noop); | ||
iterator.on('end', () => { | ||
res(); | ||
}); | ||
}); | ||
} | ||
|
||
function baseIterator() { | ||
let i = 0; | ||
return new ArrayIterator(new Array(20000000).fill(true).map(() => i++)); | ||
} | ||
|
||
function createMapped(filter) { | ||
let iterator = baseIterator(); | ||
for (let j = 0; j < 20; j++) { | ||
iterator = iterator.map(item => item); | ||
if (filter) | ||
iterator = iterator.filter(item => item % (j + 2) === 0); | ||
} | ||
return iterator; | ||
} | ||
|
||
(async () => { | ||
await run(baseIterator()); // warm-up run | ||
|
||
await perf(baseIterator(), createMapped(), '20000000 elems 20 maps\t\t\t\t\t'); | ||
await perf(createMapped(true), createMapped(true), '20000000 elems 20 maps 20 filter\t\t\t'); | ||
|
||
const now = performance.now(); | ||
for (let j = 0; j < 100_000; j++) { | ||
let it = range(1, 100); | ||
for (let k = 0; k < 5; k++) | ||
it = it.map(item => item); | ||
|
||
await new Promise((resolve, reject) => { | ||
it.on('data', () => null); | ||
it.on('end', resolve); | ||
it.on('error', reject); | ||
}); | ||
} | ||
console.log('100_000 iterators each with 5 maps and 100 elements\t', performance.now() - now); | ||
})(); |
Oops, something went wrong.