Skip to content

Commit

Permalink
feat: finish bench use @rolldown/core (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
houyunlu committed Nov 13, 2023
1 parent 42420d7 commit aa7982b
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 21 deletions.
14 changes: 14 additions & 0 deletions bench/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const esbuild = require('esbuild')
const path = require('path')

async function esbuildBundle(entryPoints) {
await esbuild.build({
entryPoints: entryPoints,
bundle: true,
outfile: 'out.js',
})
}

module.exports = {
esbuildBundle,
}
26 changes: 26 additions & 0 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const b = require('benny')
const chalk = require('chalk')
const { rolldownBundle } = require('./rolldown')
const { esbuildBundle } = require('./esbuild')

const sleep = function () {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, 1000)
})
}

module.exports = b.suite(
'Suite two',

b.add('rolldown/three.js', async () => {
await rolldownBundle(['../temp/three.js/src/Three.js'])
}),

b.add('esbuild/three.js', async () => {
await esbuildBundle()
}),
b.cycle(),
b.complete(),
)
9 changes: 9 additions & 0 deletions bench/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"devDependencies": {
"@rolldown/core": "0.1.4",
"benchmark": "^2.1.4",
"benny": "^3.7.1",
"chalk": "^4",
"esbuild": "^0.19.5"
}
}
13 changes: 13 additions & 0 deletions bench/rolldown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const rolldown = require('@rolldown/core')

async function rolldownBundle(input) {
const bundler = await rolldown.rolldown({
input,
})
let res = await bundler.generate()
return res
}

module.exports = {
rolldownBundle,
}
43 changes: 25 additions & 18 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
set shell := ["bash", "-cu"]

_default:
just --list -u
just --list -u

init:
cargo binstall rusty-hook taplo-cli cargo-insta cargo-nextest -y
yarn install
git submodule update
cargo binstall rusty-hook taplo-cli cargo-insta cargo-nextest -y
yarn install
git submodule update

test:
cargo nextest run --no-fail-fast
cargo nextest run --no-fail-fast

lint:
cargo clippy --all -- --deny warnings
cargo clippy --all -- --deny warnings

# Update our local branch with the remote branch (this is for you to sync the submodules)
update:
git pull
git submodule update --init
git pull
git submodule update --init

fmt:
cargo fmt
taplo format
npm run prettier
cargo fmt
taplo format
npm run prettier

bench-prepare:
git clone https://github.com/mrdoob/three.js.git --depth 1 ./temp/three.js
for i in {1..10}; do cp -r ./temp/three.js/src ./temp/three.js/copy$i/; done

git clone https://github.com/mrdoob/three.js.git --depth 1 ./temp/three.js
for i in {1..10}; do cp -r ./temp/three.js/src ./temp/three.js/copy$i/; done

# build node binding
build-binding mode="debug":
yarn workspace @rolldown/node-binding run {{ if mode == "release" { "build:release" } else { "build" } }}

bench:
cargo bench -p bench
cargo bench -p bench

# build wasm of rolldown and move the output `pkg/` under `web` directory

# Use `just wasm-build release` for better performance but also it will cost more time.
wasm-build mode="dev":
cd crates/rolldown_wasm && wasm-pack build --{{mode}} --target web
-rm -r ./web/wasm
mv crates/rolldown_wasm/pkg ./web/wasm
cd crates/rolldown_wasm && wasm-pack build --{{ mode }} --target web
-rm -r ./web/wasm
mv crates/rolldown_wasm/pkg ./web/wasm
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"workspaces": [
"crates/rolldown_binding",
"packages/**",
"web/**"
"web/**",
"bench"
],
"scripts": {
"lint": "oxlint --ignore-path=./.oxlintignore --import-plugin",
Expand Down
16 changes: 14 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ __metadata:
languageName: node
linkType: hard

"@rolldown/core@workspace:*, @rolldown/core@workspace:packages/core":
"@rolldown/core@0.1.4, @rolldown/core@workspace:*, @rolldown/core@workspace:packages/core":
version: 0.0.0-use.local
resolution: "@rolldown/core@workspace:packages/core"
dependencies:
Expand Down Expand Up @@ -2711,6 +2711,18 @@ __metadata:
languageName: node
linkType: hard

"bench-67b55d@workspace:bench":
version: 0.0.0-use.local
resolution: "bench-67b55d@workspace:bench"
dependencies:
"@rolldown/core": 0.1.4
benchmark: ^2.1.4
benny: ^3.7.1
chalk: ^4
esbuild: ^0.19.5
languageName: unknown
linkType: soft

"benchmark@npm:^2.1.4":
version: 2.1.4
resolution: "benchmark@npm:2.1.4"
Expand Down Expand Up @@ -4267,7 +4279,7 @@ __metadata:
languageName: node
linkType: hard

"esbuild@npm:^0.19.2":
"esbuild@npm:^0.19.2, esbuild@npm:^0.19.5":
version: 0.19.5
resolution: "esbuild@npm:0.19.5"
dependencies:
Expand Down

0 comments on commit aa7982b

Please sign in to comment.