Skip to content

Commit

Permalink
[benchmarks] Add regcomp-cache synthetic stress test
Browse files Browse the repository at this point in the history
Unrelated: add more types and functions to doc/ref
  • Loading branch information
Andy C committed Dec 20, 2023
1 parent 686dc1a commit 31e01f1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
44 changes: 44 additions & 0 deletions benchmarks/regcomp-cache/run.sh
@@ -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"
}


"$@"

10 changes: 6 additions & 4 deletions doc/ref/toc-ysh.md
Expand Up @@ -247,15 +247,17 @@ X [Builtin Sub] _buffer
X insert() X remove() reverse()
[Dict] keys() values() X get() X erase()
X inc() X accum()
X [Func] toJson()
X [Proc] toJson()
X [Func] name() location() toJson()
X [Proc] name() location() toJson()
X [Module] name() filename()
[Place] setValue()
[IO] X eval() X captureStdout()
promptVal()
X time() X strftime()
X glob()
[Quotation] Expr X Template Command
[Code] BuiltinFunc BuiltinMethod
X [Guts] addr() id()
```

<h2 id="builtin-func">
Expand All @@ -265,8 +267,8 @@ X [Proc] toJson()
```chapter-links-builtin-func
[Values] len() type()
[Conversions] bool() int() float() str() list() dict()
X chr() X ord()
X runes()
X chr() X ord() X runes()
X guts()
[Str] strcmp()
[List] any() all()
[Collections] join() X split() X shSplit()
Expand Down

0 comments on commit 31e01f1

Please sign in to comment.