{"id":16528560,"url":"https://github.com/danvk/async-iteration","last_synced_at":"2025-09-12T19:32:04.754Z","repository":{"id":24278232,"uuid":"101090369","full_name":"danvk/async-iteration","owner":"danvk","description":"Experiments with async iterators","archived":false,"fork":false,"pushed_at":"2023-09-27T20:43:09.000Z","size":4101,"stargazers_count":3,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-03T03:50:13.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danvk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-22T17:35:05.000Z","updated_at":"2024-12-30T13:48:27.000Z","dependencies_parsed_at":"2022-07-25T13:52:12.641Z","dependency_job_id":null,"html_url":"https://github.com/danvk/async-iteration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Fasync-iteration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Fasync-iteration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Fasync-iteration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Fasync-iteration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danvk","download_url":"https://codeload.github.com/danvk/async-iteration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232780145,"owners_count":18575474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T17:40:51.564Z","updated_at":"2025-01-06T20:04:53.390Z","avatar_url":"https://github.com/danvk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async Iteration Playground\n\nSee [my post][1] about [async iterators][2] on Medium from 2017. Things have gotten considerably better in Node land since that post was written.\n\n## Quickstart\n\n    yarn\n    ./node_modules/.bin/ts-node async-iter.ts\n    python line_reader.py\n    python csv_reader.py\n\n## Results (2023)\n\nPlay around with your node version and `target` in `tsconfig.json` to see how this is getting better.\n\nWith Node 18.8.0:\n\n```\n$ ts-node async-iter.ts\nrange sync: 8 ms\nrange async: 54 ms\nlines async: 117 ms\nlines async chunked: 43 ms\nlines sync: 58 ms\n```\n\nWith Node 16.19.1:\n\n```\n$ ts-node async-iter.ts\nrange sync: 8 ms\nrange async: 56 ms\nlines async: 132 ms\nlines async chunked: 46 ms\nlines sync: 62 ms\n```\n\nNow on a 2022 M2 MacBook Air with node 14.17.1, TypeScript 3.9 and `\"target\": \"esnext\"`:\n\n```\n$ ts-node async-iter.ts\nrange sync: 19 ms\nrange async: 62 ms\nlines async: 154 ms\nlines async chunked: 78 ms\nlines sync: 96 ms\n```\n\nCompare with Python 3.11.4:\n\n```\n$ python line_reader.py\nRead 549996 lines, 32871385 bytes in 0.099241 s\n$ python csv_reader.py\nRead 549996 lines, 4949964 cells in 0.349307 s\n```\n\nSo in 2023, Python 3.11 and Node 18.8 are within about 20% of one another (117ms for \"range async\" in Node vs. 99ms for Python).\n\n### Older Results (2017–2020)\n\nWith node 14.2.0, TypeScript 3.9 and `\"target\": \"esnext\"`:\n\n```\n$ ts-node async-iter.ts\nrange sync: 21 ms\nrange async: 125 ms\nlines async: 299 ms\nlines async chunked: 132 ms\nlines sync: 169 ms\n```\n\nWith node 12.16.2, TypeScript 3.9 and `\"target\": \"esnext\"`:\n\n```\n$ ts-node async-iter.ts\nrange sync: 31 ms\nrange async: 136 ms\nlines async: 338 ms\nlines async chunked: 197 ms\nlines sync: 184 ms\n```\n\nWith node 10.1.0, TypeScript 2.8 and `\"target\": \"esnext\"`:\n\n```\n$ ./node_modules/.bin/ts-node async-iter.ts\nrange sync: 30 ms\nrange async: 172 ms\nlines async: 621 ms\nlines async chunked: 283 ms\nlines sync: 358 ms\n```\n\nvs. node 8.11.2 and `\"target\": \"es6\"`:\n\n```\n$ ./node_modules/.bin/ts-node async-iter.ts\nrange sync: 30 ms\nrange async: 1408 ms\nlines async: 1800 ms\nlines async chunked: 236 ms\nlines sync: 370 ms\n```\n\nSo the simplest `for await of` loop has gotten ~8x faster and the async csv\nparser has gotten ~3x faster.\n\nFor comparison, Python 3.6.5 reads the same file in 145ms:\n\n```\n$ python3.6 line_reader.py\nRead 549996 lines, 32871385 bytes in 0.295456 s\n$ python3.7 csv_reader.py\nRead 549996 lines, 4949964 cells in 0.936364 s\n```\n\n[1]: https://medium.com/p/4767df03d85b/\n[2]: https://github.com/tc39/proposal-async-iteration\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanvk%2Fasync-iteration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanvk%2Fasync-iteration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanvk%2Fasync-iteration/lists"}