Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[demo] Benchmark for glob, examine greedy .*
- Loading branch information
Andy Chu
committed
Jul 5, 2020
1 parent
50d308d
commit a1ddd55
Showing
2 changed files
with
197 additions
and
11 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,54 @@ | ||
# | ||
# Portable Library | ||
# | ||
|
||
readonly GLOB_TMP=_tmp/glob-backtrack | ||
|
||
repeat() { | ||
local s=$1 | ||
local n=$2 | ||
|
||
for i in $(seq $n); do | ||
echo -n "$s" | ||
done | ||
} | ||
|
||
glob_bench() { | ||
local max=${1:-5} | ||
cd $GLOB_TMP | ||
|
||
for i in $(seq $max); do | ||
local pat="$(repeat 'a*' $i)b" | ||
time echo $pat | ||
echo | ||
done | ||
} | ||
|
||
fnmatch_task() { | ||
local text=$1 | ||
local pat=$2 | ||
|
||
case $text in | ||
($pat) | ||
echo yes | ||
;; | ||
(*) | ||
echo no | ||
;; | ||
esac | ||
} | ||
|
||
fnmatch_bench() { | ||
local max=${1:-5} | ||
cd $GLOB_TMP | ||
|
||
local text=$(repeat a 100) | ||
for i in $(seq $max); do | ||
local pat="$(repeat 'a*' $i)b" | ||
time fnmatch_task "$text" "$pat" | ||
|
||
echo | ||
done | ||
} | ||
|
||
|
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