Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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.
```