Skip to content

Commit

Permalink
chore: add some benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Oct 14, 2023
1 parent 6158903 commit d3df08d
Show file tree
Hide file tree
Showing 26 changed files with 495 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ zap i jquery2@npm:jquery@2
zap i jquery3@npm:jquery@3
```

# Benchmarks

**See:** [https://github.com/elbywan/zap/tree/main/bench](/bench)

## Methodology

Benchmarks consist on installing a fresh [create-react-app](https://create-react-app.dev/) in various scenarii, with postinstall scripts disabled.

They are performed on my own personal laptop (macbook pro 16" 2019, 2,3 GHz Intel Core i9, 16 Go 2667 MHz DDR4) with 5G wifi and 1 Gb/s fiber.

The benchmarking tool is [hyperfine](https://github.com/sharkdp/hyperfine) and to make sure that the results are consistent I re-ran unfavorable results (high error delta).

I am aware that this is not a very scientific approach, but it should give rough good idea about what zap is capable of.

## Results

![cold](bench/cold.png)
![only-cache](bench/only-cache.png)
![without-lockfile](bench/without-lockfile.png)
![without-node-modules](bench/without-node-modules.png)

## Why?

**This is a legitimate question.** There are already a lot of package managers out there, and they all have their own pros and cons. So why another one?
Expand Down
41 changes: 41 additions & 0 deletions bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Benchmarks

## Setup

Install and make sure the binaries are in your path:

- [npm](https://www.npmjs.com/)
- [yarn](https://yarnpkg.com/)
- [pnpm](https://pnpm.io/)
- [bun](bun.sh/)
- [zap](https://github.com/elbywan/zap)

### With the [proto](https://moonrepo.dev/proto) tool

The proto tool can be used to install the dependencies easily.

```bash
proto install node latest
proto install python latest
proto install npm latest
proto install pnpm latest
proto install yarn latest
proto install bun latest
```

## Dependencies

Plotting requires python and the following dependencies:

```bash
pip install numpy matplotlib
```

## Run

```bash
# Run the benchmarks
./bench.sh
# Plot the results
./plot.sh
```
51 changes: 51 additions & 0 deletions bench/bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

cd react-app

hyperfine \
--warmup 1 \
--runs 3 \
--export-json cold.json \
--prepare 'rm -Rf node_modules .yarn $(pnpm store path) ~/.bun/ package-lock.json pnpm-lock.yaml yarn.lock bun.lockb zap.lock; yarn cache clean --all; npm cache clean --force; zap store clear; true' \
'npm i --ignore-scripts --no-audit' \
'env YARN_ENABLE_SCRIPTS=false YARN_NODE_LINKER=node-modules yarn' \
'pnpm i --ignore-scripts' \
'bun i --ignore-scripts' \
'zap i --ignore-scripts'

hyperfine \
--warmup 1 \
--runs 3 \
--export-json only-cache.json \
--prepare 'rm -Rf node_modules package-lock.json pnpm-lock.yaml yarn.lock bun.lockb zap.lock; true' \
'npm i --ignore-scripts --no-audit' \
'env YARN_ENABLE_SCRIPTS=false YARN_NODE_LINKER=node-modules yarn' \
'pnpm i --ignore-scripts' \
'bun i --ignore-scripts' \
'zap i --ignore-scripts'

hyperfine \
--warmup 1 \
--runs 3 \
--export-json without-lockfile.json \
--prepare 'rm -f package-lock.json pnpm-lock.yaml yarn.lock bun.lockb zap.lock; true' \
'npm i --ignore-scripts --no-audit' \
'env YARN_ENABLE_SCRIPTS=false YARN_NODE_LINKER=node-modules yarn' \
'pnpm i --ignore-scripts' \
'bun i --ignore-scripts' \
'zap i --ignore-scripts'

hyperfine \
--warmup 1 \
--runs 3 \
--export-json without-node-modules.json \
--prepare 'rm -Rf node_modules; true' \
'npm i --ignore-scripts --no-audit' \
'env YARN_ENABLE_SCRIPTS=false YARN_NODE_LINKER=node-modules yarn' \
'pnpm i --ignore-scripts' \
'bun i --ignore-scripts' \
'zap i --ignore-scripts'

rm -Rf node_modules .yarn package-lock.json pnpm-lock.yaml yarn.lock bun.lockb zap.lock

cd -
Binary file added bench/cold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/only-cache.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions bench/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import argparse
import json
import matplotlib.pyplot as plt
import numpy as np

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", help="JSON file with benchmark results")
parser.add_argument("--title", help="Plot title")
parser.add_argument(
"--labels", help="Comma-separated list of entries for the plot legend"
)
parser.add_argument("-o", "--output", help="Save image to the given filename.")

args = parser.parse_args()

with open(args.file) as f:
results = json.load(f)["results"]

if args.labels:
labels = args.labels.split(",")
else:
labels = [b["command"] for b in results]
times = [b["mean"] for b in results]

fig, ax = plt.subplots()

# Example data
y_pos = np.arange(len(labels))
error = [b["stddev"] for b in results]

ax.barh(y_pos, times, xerr=error, align='center')
ax.set_yticks(y_pos, labels=labels)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel('Time (s)')

if args.title:
plt.title(args.title)

if args.output:
fig = plt.gcf()
fig.tight_layout()
plt.savefig(args.output)
else:
plt.show()
13 changes: 13 additions & 0 deletions bench/plot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

NPM_LABEL="npm v$(npm --version)"
YARN_LABEL="yarn v$(yarn --version)"
PNPM_LABEL="pnpm v$(pnpm --version)"
BUN_LABEL="bun v$(bun --version)"
ZAP_LABEL="zap $(zap --version)"
LABELS="$NPM_LABEL,$YARN_LABEL (node linker),$PNPM_LABEL,$BUN_LABEL,$ZAP_LABEL"

python3 plot.py -o cold.png --labels "$LABELS" --title "Without cache, lockfile or node modules" ./react-app/cold.json
python3 plot.py -o only-cache.png --labels "$LABELS" --title "Without lockfile or node modules" ./react-app/only-cache.json
python3 plot.py -o without-lockfile.png --labels "$LABELS" --title "Without lockfile" ./react-app/without-lockfile.json
python3 plot.py -o without-node-modules.png --labels "$LABELS" --title "Without node modules" ./react-app/without-node-modules.json
26 changes: 26 additions & 0 deletions bench/react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/*.json
!/package.json
70 changes: 70 additions & 0 deletions bench/react-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
38 changes: 38 additions & 0 deletions bench/react-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added bench/react-app/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions bench/react-app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added bench/react-app/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/react-app/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions bench/react-app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions bench/react-app/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
Loading

0 comments on commit d3df08d

Please sign in to comment.