1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-10-18 19:49:40 +00:00

benchmarks/shellbench: add new port

This program allows to compare the performance of different POSIX
shells (e.g. sh, bash, dash, ksh, zsh, ...).

A number of sample scripts are included and can be easily extended to
cover more areas.
This commit is contained in:
Stefan Eßer 2021-09-23 12:17:26 +02:00
parent 72840ac5c3
commit 05857c1ba0
6 changed files with 130 additions and 0 deletions

View File

@ -85,6 +85,7 @@
SUBDIR += scimark2c
SUBDIR += siege
SUBDIR += sipp
SUBDIR += shellbench
SUBDIR += slowloris
SUBDIR += smhasher
SUBDIR += spp

View File

@ -0,0 +1,29 @@
PORTNAME= shellbench
PORTVERSION= 20200806
CATEGORIES= benchmarks
MAINTAINER= se@FreeBSD.org
COMMENT= Benchmark utility for POSIX shell comparison
LICENSE= MIT
LICENSE_FILE= ${WRKSRC}/LICENSE
USE_GITHUB= yes
GH_ACCOUNT= shellspec
GH_TAGNAME= ce43ba49d3
NO_ARCH= yes
NO_BUILD= yes
OPTIONS_DEFINE= DOCS
do-install:
${REINPLACE_CMD} 's:%%DATADIR%%:${DATADIR}:g' ${WRKSRC}/shellbench
${REINPLACE_CMD} 's:%%DOCSDIR%%:${DOCSDIR}:g' ${WRKSRC}/shellbench
${INSTALL_SCRIPT} ${WRKSRC}/shellbench ${STAGEDIR}${PREFIX}/bin
${MKDIR} ${STAGEDIR}${DATADIR}
${INSTALL_DATA} ${WRKSRC}/sample/* ${STAGEDIR}${DATADIR}/
${MKDIR} ${STAGEDIR}${DOCSDIR}
${INSTALL_DATA} ${WRKSRC}/README.md ${STAGEDIR}${DOCSDIR}/
.include <bsd.port.mk>

View File

@ -0,0 +1,3 @@
TIMESTAMP = 1632383851
SHA256 (shellspec-shellbench-20200806-ce43ba49d3_GH0.tar.gz) = 84abc9341c79092c1818d5f8bfa72566374fb011550b969c86d2f3bef23a5e4f
SIZE (shellspec-shellbench-20200806-ce43ba49d3_GH0.tar.gz) = 7379

View File

@ -0,0 +1,80 @@
--- shellbench.orig 2020-08-06 15:07:20 UTC
+++ shellbench
@@ -12,6 +12,8 @@ COUNT_WIDTH=${SHELLBENCH_COUNT_WIDTH:-10}
SHOW_ERROR=''
CORRECTION_MODE=''
NULLLOOP_COUNT=''
+ALL_SAMPLES=''
+SAMPLE_DIR=%%DATADIR%%
usage() {
cat<<HERE
@@ -20,10 +22,19 @@ Usage: shellbench [options] files...
-s, --shell SHELL[,SHELL...] The shell(s) to run the benchmark. [default: sh]
-t, --time SECONDS Benchmark execution time. (SECONDS > 0) [default: 3]
-w, --warmup SECONDS Benchmark preparation time. (SECONDS > 0) [default: 1]
+ -a, --allsamples Execute all sample scripts
-c, --correct Enable correction mode to eliminate loop overhead.
-e, --error Display error details.
-h, --help You're looking at it.
+ -l, --listsamples List names of the sample scripts
+
+The sample scripts can be found in %%DATADIR%% .
HERE
+if [ -r "%%DOCSDIR%%/README.md" ]; then
+cat<<HERE
+Their format is documented in %%DOCSDIR%%/README.md .
+HERE
+fi
}
preprocess() {
@@ -313,6 +324,14 @@ display_footer() {
PARAMS=''
+all_samples() {
+ PARAMS="$PARAMS "$(echo %%DATADIR%%/*.sh)
+}
+
+list_samples() {
+ cd %%DATADIR%%; echo *.sh
+}
+
abort() { echo "$@" >&2; exit 1; }
unknown() { abort "Unrecognized option '$1'"; }
required() { [ $# -gt 1 ] || abort "Option '$1' requires an argument"; }
@@ -327,9 +346,11 @@ parse_options() {
-s | --shell ) required "$@" && shift; SHELLS=$1 ;;
-t | --time ) required "$@" && shift; BENCHMARK_TIME=$1 ;;
-w | --warmup ) required "$@" && shift; WARMUP_TIME=$1 ;;
+ -a | --allsamples ) ALL_SAMPLES=1 ;;
-c | --correct) CORRECTION_MODE=1 ;;
-e | --error ) SHOW_ERROR=1 ;;
-h | --help ) usage; exit ;;
+ -l | --listsamples ) list_samples; exit ;;
--) shift; params PARAMS $(($OPTIND - $#)) $OPTIND; break ;;
-?*) unknown "$@" ;;
*) param PARAMS $(($OPTIND - $#))
@@ -342,6 +363,11 @@ ${__SOURCED__:+return}
trap '' HUP
parse_options "$@"
+
+[ "$ALL_SAMPLES" ] && all_samples
+
+[ -z "$PARAMS" ] && { usage; exit; }
+
eval "set -- $PARAMS"
[ "$CORRECTION_MODE" ] && NULLLOOP_COUNT=${SHELLBENCH_NULLLOOP_COUNT:-}
@@ -352,6 +378,9 @@ display_header "$SHELLS"
$(printf '%s\n' '#bench "loop only"' '@begin' '@end' | preprocess)
HERE
for file in "$@"; do
+ [ -r "$file" ] || if [ -r "%%DATADIR%%/$file" ]; then
+ file="%%DATADIR%%/$file"
+ fi
preprocess < "$file" | process "${file##*/}"
done
display_footer

View File

@ -0,0 +1,7 @@
Shellbench is a benchmark utility for POSIX shell comparison.
It allows to compare the performance of shell commands and operations
and comes with a set of sample scripts. Supported shells are sh, bash,
dash, ksh, zsh and many more.
WWW: https://github.com/shellspec/shellbench

View File

@ -0,0 +1,10 @@
bin/shellbench
%%PORTDOCS%%%%DOCSDIR%%/README.md
%%DATADIR%%/assign.sh
%%DATADIR%%/cmp.sh
%%DATADIR%%/count.sh
%%DATADIR%%/eval.sh
%%DATADIR%%/func.sh
%%DATADIR%%/null.sh
%%DATADIR%%/output.sh
%%DATADIR%%/subshell.sh