Skip to content

Commit ac414a8

Browse files
committed
add bash script to run a benchmark
1 parent 35c91c6 commit ac414a8

File tree

1 file changed

+51
-0
lines changed
  • packages/next-swc/crates/next-build-test

1 file changed

+51
-0
lines changed

Diff for: packages/next-swc/crates/next-build-test/bench.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# run a benchmark against this binary
4+
# using heaptrack to extract memory
5+
# usage numbers at g-max
6+
7+
set -e
8+
9+
COMMIT=${1:-HEAD} # the sha of the commit to benchmark
10+
PAGES=${2:-0} # the number of pages to build
11+
12+
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
13+
14+
# build the binary
15+
cargo build --profile release-with-debug --manifest-path "$SCRIPTPATH/Cargo.toml"
16+
17+
# create the config file by loading the default config and adding the required fields
18+
JS_CONFIG=$(cat "$SCRIPTPATH/jsConfig.json")
19+
NEXT_CONFIG=$(cat "$SCRIPTPATH/nextConfig.json")
20+
21+
# create a temp dir and clone shadcn-ui into it
22+
TMPDIR=$(mktemp -d)
23+
git clone https://github.com/shadcn-ui/ui.git "$TMPDIR"
24+
cd "$TMPDIR"
25+
git checkout "$COMMIT"
26+
27+
# install the dependencies
28+
pnpm install
29+
30+
# create the project options file
31+
jq -n --arg jsConfig "$JS_CONFIG" --arg nextConfig "$NEXT_CONFIG" --arg tmpDir "$TMPDIR" '{
32+
rootPath: $tmpDir,
33+
projectPath: ($tmpDir + "/apps/www"),
34+
jsConfig: $jsConfig,
35+
nextConfig: $nextConfig,
36+
watch: false,
37+
dev: false,
38+
env: [],
39+
defineEnv: {
40+
client: [],
41+
edge: [],
42+
nodejs: []
43+
}
44+
}' > project_options.json
45+
46+
# heaptrack the binary with the project options in raw mode
47+
heaptrack --record-only "$SCRIPTPATH/../../../../target/release-with-debug/next-build-test" concurrent 12 "$PAGES"
48+
49+
# get most recently created heaptrack profile and run it via heaptrack_print
50+
PROFILE=$(ls -t "$TMPDIR/heaptrack.*" | head -n1)
51+
heaptrack_print "$PROFILE" > "$SCRIPTPATH/result.log"

0 commit comments

Comments
 (0)