Created
May 13, 2020 13:56
-
-
Save open-dynaMIX/b68959d23246442ad47fd1e1209794f5 to your computer and use it in GitHub Desktop.
Anonip profiling - column based vs. regex based IP detection
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
#!/usr/bin/env bash | |
n_runs=10 | |
if ! [ -z ${1+x} ]; then | |
n_runs="$1" | |
fi | |
run () { | |
result=0 | |
for _ in $(seq 1 $n_runs); do | |
res=$(python -m cProfile ./anonip.py "$@" --input ./access.log | grep "function calls" | awk '{print $8}') | |
result=$(echo "$result + $res" | bc) | |
done | |
echo "$(echo "$result / $n_runs" | bc -l | grep -o '.*[1-9]' | sed 's/^\./0./')" | |
} | |
regex_result=$(run --regex "(?:^(.*) - - |.* - somefixedstring\: (.*) - .* - (.*))") | |
column_result=$(run) | |
diff=$(echo "scale=2;100 - (100 * $column_result / $regex_result)" | bc -l | sed 's/^\./0./') | |
echo "regex based: $regex_result seconds average" | |
echo "column based: $column_result seconds average" | |
echo "column based detection is ${diff}% faster than regex based detection" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment