Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bastidood/js-generators-vs-array-methods
The repository for all the scripts, notebooks, results, and analyses related to my experiments on JavaScript generators and chained array methods.
https://github.com/bastidood/js-generators-vs-array-methods
bun deno javascript node notebook python
Last synced: about 1 month ago
JSON representation
The repository for all the scripts, notebooks, results, and analyses related to my experiments on JavaScript generators and chained array methods.
- Host: GitHub
- URL: https://github.com/bastidood/js-generators-vs-array-methods
- Owner: BastiDood
- License: mit
- Created: 2024-09-08T13:49:06.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-09T01:18:30.000Z (4 months ago)
- Last Synced: 2024-11-22T23:10:05.181Z (about 1 month ago)
- Topics: bun, deno, javascript, node, notebook, python
- Language: Jupyter Notebook
- Homepage: https://dev.to/somedood/i-was-wrong-about-array-methods-and-generators-2ig9
- Size: 1.01 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JavaScript Generators vs. Array Methods
The repository for all the scripts, notebooks, results, and analyses related to my experiments on JavaScript generators and chained array methods. See the full article ["I was wrong about array methods and generators..."][article] for more details on the methodology, results, interpretations, and conclusions.
[article]: https://dev.to/somedood/i-was-wrong-about-array-methods-and-generators-2ig9
## Generating Random Bytes
The first step is to generate 32 KiB of random data. There are many ways to do this, but I opted to generate them via the [`Crypto#getRandomValues`] function in JavaScript. A Deno script is already available at [`random/random.js`].
[`Crypto#getRandomValues`]: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
[`random/random.js`]: random/random.js```bash
# This will overwrite the already existing `random.bin` file!
deno run random/random.js
```## Running the Experiments
```bash
# Node.js
function run () { node --experimental-default-type=module benchmark/bench.node.js $1 > notebook/node/$1.csv; }
run raw-for-loop
run for-of-loop
run array-method
run generator
``````bash
# Deno
function run () { deno --quiet --allow-read --allow-hrtime benchmark/bench.deno.js -- $1 > notebook/deno/$1.csv; }
run raw-for-loop
run for-of-loop
run array-method
run generator
``````bash
# Bun
function run () { bun --silent benchmark/bench.bun.js $1 > notebook/bun/$1.csv; }
run raw-for-loop
run for-of-loop
run array-method
run generator
```## Analyzing the Data
The Python notebook containing the data analysis is located at [`notebook/analysis.ipynb`].
[`notebook/analysis.ipynb`]: notebook/analysis.ipynb
```bash
conda env create --file notebook/environment.yml
conda activate js-generators-vs-array-methods
# You may now run the Python notebook.
```