mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
366c50674c
easily compare v performance/size across commits. * fix eprintln on linux (it now uses stderr, and flushes it). * flag: cleaner usage information.
99 lines
2.6 KiB
Bash
Executable File
99 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
msg() {
|
|
printf '%s\n' "$*";
|
|
}
|
|
|
|
if [ $# -ne 2 ]; then
|
|
msg "Usage: compare_v_to_c_performance COMMIT_BEFORE COMMIT_AFTER"
|
|
exit 1
|
|
fi
|
|
|
|
depend_on() {
|
|
type "$1" >/dev/null 2>&1 || {
|
|
printf 'ERR: missing tool "%s"\n' "$1" >&2; exit 1;
|
|
}
|
|
}
|
|
|
|
depend_on sh
|
|
depend_on cp
|
|
depend_on rm
|
|
depend_on wc
|
|
depend_on head
|
|
depend_on cc
|
|
depend_on strip
|
|
depend_on git
|
|
depend_on upx
|
|
depend_on make
|
|
depend_on hyperfine
|
|
|
|
######################################################################
|
|
## NB: cc should be a working, recent, sane C99 compiler
|
|
## cc is used by the Makefile to bootstrap v (both gcc/clang work)
|
|
##
|
|
## If you are a C/V developer in a unix environment, you most probably
|
|
## already have the above installed, with the possible exception of:
|
|
## https://github.com/sharkdp/hyperfine
|
|
##
|
|
## Installing them is out of scope of this tool.
|
|
######################################################################
|
|
|
|
COMMIT_B="$1"
|
|
COMMIT_A="$2"
|
|
|
|
CWD="$(pwd)"
|
|
WORKDIR="/tmp"
|
|
|
|
B="$WORKDIR/v_at_$COMMIT_B"
|
|
A="$WORKDIR/v_at_$COMMIT_A"
|
|
|
|
prepare_v() {
|
|
msg
|
|
msg "Cloning current v source to $1 ..."
|
|
git clone --quiet "$CWD" "$1"
|
|
|
|
cd "$1"
|
|
git checkout --quiet "$2"
|
|
|
|
msg "Making v and vprod compilers in $1"
|
|
make > /dev/null
|
|
./v -o v compiler
|
|
./v -prod -o vprod compiler
|
|
cp v v_stripped
|
|
cp vprod vprod_stripped
|
|
strip *_stripped
|
|
cp v_stripped v_stripped_upxed
|
|
cp vprod_stripped vprod_stripped_upxed
|
|
upx -qqq --lzma v_stripped_upxed
|
|
upx -qqq --lzma vprod_stripped_upxed
|
|
wc -c "$1/v" "$1/v_stripped" "$1/v_stripped_upxed" "$1/vprod" "$1/vprod_stripped" "$1/vprod_stripped_upxed" | head -n -1
|
|
VVERSION="$($1/v --version)"
|
|
GVERSION="$(git rev-parse --short --verify HEAD)"
|
|
msg "V version is: $VVERSION , local source commit: $GVERSION"
|
|
}
|
|
|
|
compare_v_performance() {
|
|
CMD="$1"
|
|
msg "---------------------------------------------------------------------------------"
|
|
msg "Compare '$CMD'"
|
|
hyperfine --warmup=3 "cd '$B/' && $CMD " "cd '$A/' && $CMD "
|
|
msg
|
|
}
|
|
|
|
##############################################################################
|
|
# Cleanup artifacts from previous runs of this tool:
|
|
cd "$WORKDIR"
|
|
rm -rf "$A/" "$B/"
|
|
##############################################################################
|
|
|
|
msg "Comparing v compiler performance of commit $COMMIT_B (before) vs commit $COMMIT_A (after) ..."
|
|
prepare_v "$B" "$COMMIT_B"
|
|
prepare_v "$A" "$COMMIT_A"
|
|
|
|
cd "$WORKDIR"
|
|
compare_v_performance "./v -o x.c compiler"
|
|
compare_v_performance "./vprod -o x.c compiler"
|
|
compare_v_performance "./vprod -o x compiler"
|