Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[benchmarks] Add regcomp-cache synthetic stress test
Unrelated: add more types and functions to doc/ref
- Loading branch information
Andy C
committed
Dec 20, 2023
1 parent
686dc1a
commit 31e01f1
Showing
2 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Synthetic test with 1000 regexes. | ||
# | ||
# Usage: | ||
# benchmarks/regcomp-cache/run.sh <function name> | ||
# | ||
# Example: | ||
# benchmarks/regcomp-cache/run.sh match-many | ||
|
||
|
||
match-many() { | ||
local num_pat=${1:-1000} | ||
local num_str=${1:-1000} | ||
|
||
declare -a REGEXES=() | ||
for i in $(seq $num_pat); do | ||
REGEXES[i]="$i?$i*$i+" # last char is modified with ? then * and + | ||
done | ||
|
||
echo "${REGEXES[@]}" | ||
|
||
local num_yes=0 | ||
local num_tried=0 | ||
|
||
for str in $(seq $num_str); do | ||
for i in $(seq $num_pat); do | ||
local re="${REGEXES[i]}" | ||
if [[ $str =~ $re ]]; then | ||
echo "string $str matches pattern $re" | ||
num_yes=$(( num_yes + 1 )) | ||
fi | ||
num_tried=$(( num_tried + 1 )) | ||
done | ||
done | ||
|
||
echo | ||
echo "num_yes = $num_yes" | ||
echo "num_tried = $num_tried" | ||
} | ||
|
||
|
||
"$@" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters