Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions maint/README
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,21 @@ pcre2_chartables.c.non-standard
characters greater than 128 that are set as spaces, amongst other things. I
kept it so that it can be used for testing from time to time.

pcre2bench.c
A benchmark driver that measures match throughput over a generated
pseudo-text corpus, for a set of patterns chosen to exercise the JIT's
start-of-match fast-forward paths. It is useful when comparing two builds of
the library, for example when adding a SIMD fast-forward implementation for
a new architecture. It is not built by any of the PCRE2 build systems; use
RunBenchmark, which compiles it. See the comments at the start of the file.

README
This file.

RunBenchmark
A script that compiles pcre2bench.c against an existing build tree and runs
it, writing TSV to stdout.

RunCoverage
A script used to generate the coverage report using Clang. It is called by
the GitHub CI actions, and can also be run by a developer locally.
Expand Down
94 changes: 94 additions & 0 deletions maint/RunBenchmark
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/sh
#
# Compile maint/pcre2bench.c, which no PCRE2 build system builds, against an
# already-built PCRE2 tree and run it.
#
# Usage: maint/RunBenchmark [-8|-16|-32] <build-dir> [label] [nojit] [short]
#
# <build-dir> is a directory in which the library has been built, by CMake or
# by autotools; both layouts are recognized. -8, -16 and -32 select the code
# unit width to benchmark, defaulting to 8; that library must have been built.
# The remaining arguments are passed to the driver, and are described at the
# start of pcre2bench.c. If no label is given, the build directory name is
# used.
#
# Output is TSV on stdout, so a comparison between two builds is
#
# maint/RunBenchmark build-before before > before.tsv
# maint/RunBenchmark build-after after > after.tsv
#
# CC and CFLAGS are honored; CFLAGS defaults to -O2.

set -eu

CC=${CC:-cc}
CFLAGS=${CFLAGS:--O2}

width=8

usage()
{
echo "usage: $0 [-8|-16|-32] <build-dir> [label] [nojit] [short]" >&2
exit 2
}

while [ $# -ge 1 ]; do
case $1 in
-8|-16|-32) width=${1#-}; shift;;
-*) usage;;
*) break;;
esac
done

[ $# -ge 1 ] || usage

build=$1
shift
[ -d "$build" ] || { echo "$0: no such directory: $build" >&2; exit 1; }
build=$(cd "$build" && pwd)
label=$(basename "$build")

here=$(cd "$(dirname "$0")" && pwd)
driver=$here/pcre2bench.c
[ -f "$driver" ] || { echo "$0: cannot find $driver" >&2; exit 1; }

# pcre2.h is generated, so it lives in the build tree, not in src.

header=$(find "$build" -name pcre2.h -print 2>/dev/null | head -1)
[ -n "$header" ] || {
echo "$0: no generated pcre2.h under $build; is it a build tree?" >&2
exit 1
}

# Autotools puts the libraries in .libs, CMake in the top of the build tree.

lib=$(find "$build" \( -name "libpcre2-$width.a" -o -name "libpcre2-$width.so" \
-o -name "libpcre2-$width.dylib" -o -name "pcre2-$width.lib" \) \
-print 2>/dev/null | head -1)
[ -n "$lib" ] || {
echo "$0: no $width-bit library under $build; has it been built?" >&2
exit 1
}

incdir=$(dirname "$header")
libdir=$(dirname "$lib")
binary=$build/pcre2bench-$width

$CC $CFLAGS -DPCRE2_CODE_UNIT_WIDTH="$width" -o "$binary" "$driver" \
-I"$incdir" -L"$libdir" "-lpcre2-$width" -Wl,-rpath,"$libdir"

# The driver takes the label as its first argument, so supply the build
# directory name unless the caller passed something that is not an option.

labelled=no
for arg in "$@"; do
case $arg in
nojit|short) ;;
*) labelled=yes ;;
esac
done
[ $labelled = yes ] || set -- "$label" "$@"

exec "$binary" "$@"

# End of RunBenchmark
Loading
Loading