Skip to content

The repository for all the scripts, notebooks, results, and analyses related to my experiments on JavaScript generators and chained array methods.

License

Notifications You must be signed in to change notification settings

BastiDood/js-generators-vs-array-methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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..." for more details on the methodology, results, interpretations, and conclusions.

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.

# This will overwrite the already existing `random.bin` file!
deno run random/random.js

Running the Experiments

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

conda env create --file notebook/environment.yml
conda activate js-generators-vs-array-methods
# You may now run the Python notebook.

About

The repository for all the scripts, notebooks, results, and analyses related to my experiments on JavaScript generators and chained array methods.

Topics

Resources

License

Stars

Watchers

Forks