arch linux pkgbuild script + automatic benchmark
thx for bringing shallot to the v3 onion land
i made a build script for arch linux, including an automated benchmark script
using hidden variables like $_foo is recommended in arch linux pkgbuild files
# Maintainer:
# Contributor: anon
# License: CC0-1.0
# for optimization
# cd $HOME/.cache/pikaur/build/mkp224o-git/mkp224o
# less OPTIMISATION.txt
# ./configure --help | grep -A29 '^Optional Features'
# configure options
_CF='' # keep this
# edit these ...
# choose filter algorithms and data types ...
_CF="$_CF --enable-intfilter" # use integers for filtering
#_CF="$_CF --enable-binsearch --enable-besort" # dictionary search
#_CF="$_CF --enable-regex" # regular expression filters
#_CF="$_CF --enable-binsearch" # binary search for many filters
# benchmark options
_bench_enabled=true
_bench_imps=(ref10 donna donna-sse2 amd64-51-30k amd64-64-24k)
_bench_time=5 # seconds per benchmark round
_bench_flags='-s -S 1 -y -o /dev/null abc' # 'abc' is a test prefix
# default ED25519 implementation
_c_best=ref10 # default, portable
#_c_best=donna # 32-bit x86 + ARM
#_c_best=donna-sse2 # 32-bit x86 sse2
#_c_best=amd64-51-30k # 64-bit x86
#_c_best=amd64-64-24k # 64-bit x86
_prefix=/usr
_pkgnamepfx=mkp224o
pkgname=${_pkgnamepfx}-git
_pkgverpfx=1.2.0
pkgver=${_pkgverpfx}r127.60eb4c0
pkgrel=1
pkgdesc='vanity address generator for tor onion v3 (ed25519) hidden services, similar to shallot'
arch=('i686' 'x86_64' 'arm')
url='https://github.com/cathugger/mkp224o'
license=('CCPL:zero') # CC0-1.0
depends=('libsodium' 'autoconf')
makedepends=('git')
provides=("$_pkgnamepfx")
conflicts=("$_pkgnamepfx")
# in microsoft-github we trust ... not
install=
source=('git+https://github.com/cathugger/mkp224o.git')
noextract=()
md5sums=('SKIP')
prepare() {
cd "$srcdir/$_pkgnamepfx"
[ "$_bench_enabled" == 'true' ] || {
echo skip benchmark. use $_c_best implementation
return
}
echo start benchmark
_S=() # array for speeds
_i=-1
_x='' # current implementation
_stat_lines=()
for _x in ${_bench_imps[*]}
do
echo benchmark implementation $_x build
_i=$(($_i + 1))
_S[$_i]=0
./autogen.sh
./configure --prefix=$_prefix $_CF --enable-$_x
make || {
echo make failed with $_x
make clean
continue
}
echo benchmark implementation $_x run
while read _line
do
echo $_line
if [ "${_line:0:1}" == '>' ]
then
_S[$_i]=$(echo "$_line" | cut -d, -f1 | cut -d: -f2 | cut -d. -f1)
#echo speed ${_S[$_i]}
_stat_lines+=("${_line:1} with $_x")
fi
done < <(
timeout -k $_bench_time $((1 + $_bench_time)) \
./mkp224o $_bench_flags 2>&1
)
make clean
done
echo stat lines
for _i in ${!_stat_lines[*]}
do
echo ${_stat_lines[$_i]}
done
echo done benchmark
for _i in ${!_S[*]}
do
printf 'speed %8i with %s\n' ${_S[$_i]} ${_bench_imps[$_i]}
done
# sort speeds array
IFS=$'\n'
_s_best=$(sort -n <<<"${_S[*]}"|tail -n 1)
unset IFS
# get best implementation
for _i in ${!_S[*]}
do
if (( $_s_best == ${_S[$_i]} ))
then
_c_best=${_bench_imps[$_i]}
break
fi
done
echo and the winner is ... $_c_best with $_s_best
}
build() {
cd "$srcdir/$_pkgnamepfx"
_CF="$_CF --enable-$_c_best"
./autogen.sh
./configure --prefix=$_prefix $_CF
make
}
package() {
cd "$srcdir/$_pkgnamepfx"
# no 'install' target in Makefile
#make DESTDIR="$pkgdir/" install
install -v -d "$pkgdir$_prefix/bin/"
install -v mkp224o "$pkgdir$_prefix/bin/"
install -v -d "$pkgdir$_prefix/share/$_pkgnamepfx/"
install -v COPYING.txt OPTIMISATION.txt README.txt "$pkgdir$_prefix/share/$_pkgnamepfx/"
}
pkgver() {
cd "$srcdir/$_pkgnamepfx"
# Git, no tags available
printf "%sr%s.%s" ${_pkgverpfx} "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}
in arch linux save the script as pkgbuild-mkp224o-git.txt run pikaur -Pi pkgbuild-mkp224o-git.txt
imo it could, instead of abusing prepare() for benchmarking, build all of versions in build(), and then abuse package() for benchmarking. would look a bit more right to me.
if build system could do out-of-tree builds, that would be even better for this.
that's something I sorta was thinking about adding (or using something else than autoconf for this), but was too busy with unrelated projects.
# ./configure --help | grep -A29 '^Optional Features' - -A29 isn't forward compatible. should somehow print from that line up to blank line but I'm too lazy atm to think of command for that. not to mention it's comment so not really relevant for anything.
_bench_flags='-s -S 1 -y -o /dev/null abc' # 'abc' is a test prefix - I'm not sure this needs to look so complicated: -S enables statistical output on its own (so -s is redundant), and if statistical output is enabled, mkp224o allow starting with no filters, which results in never dumping keys anywhere (which is not documented anywhere, but thing what makes sense, so it'll stay), so it all can be simplified to just -S 1.
even tho I use arch myself, I don't really feel need use pkgbuild for this personally, as this stuff usually needs some case-by-base tuning, for example, binary search works well for big dictionaries, but is pointless for something like 7 filters, and can even perform worse. and what some people actually need is regex, which would perform worse than intfilter for simple cases... so not really sure what to do with this... do you wanna to put it in something like contrib/ directory, or maybe publish it in AUR?
oh also thanks for mention of pikaur, it feels quite better than pacaur.