Add test-perf script

This commit is contained in:
Chris Down 2017-01-06 10:48:02 +00:00
parent 2ab5b5b502
commit 7987dd1757

90
test/test-perf Executable file
View file

@ -0,0 +1,90 @@
#!/bin/bash
msg() {
printf '>>> %s\n' "$@" >&2
}
dir=/tmp/clipmenu.$USER
cache_file=$dir/line_cache
log=$(mktemp)
tim=$(mktemp)
clipmenu_shim=$(mktemp)
num_files=1500
trap 'rm -f -- "$log" "$tim" "$clipmenu_shim"' EXIT
if [[ $0 == /* ]]; then
location=${0%/*}
else
location=$PWD/${0#./}
location=${location%/*}
fi
msg 'Setting up edited clipmenu'
cat - "$location/../clipmenu" > /tmp/clipmenu << EOF
#!/bin/bash
exec 3>&2 2> >(tee "$log" |
sed -u 's/^.*$/now/' |
date -f - +%s.%N > "$tim")
set -x
shopt -s expand_aliases
alias dmenu=:
alias xsel=:
alias xclip=:
EOF
chmod a+x /tmp/clipmenu
if ! (( NO_RECREATE )); then
rm -rf "$dir"
mkdir -p "$dir"
msg "Writing $num_files clipboard files"
for (( i = 0; i <= num_files; i++ )); do
(( i % 100 )) || printf '%s... ' "$i"
line_len=$(( (RANDOM % 10000) + 1 ))
num_lines=$(( (RANDOM % 10) + 1 ))
fn=$dir/$(LC_ALL=C date +%F-%T.%N)
data=$(
tr -dc 'a-zA-Z0-9' < /dev/urandom |
fold -w "$line_len" |
head -"$num_lines"
)
printf '%s' "$data" > "$fn"
read -r first_line <<< "$data"
printf '%s|%s (%s lines)\n' \
"$fn" "$first_line" "$num_lines" >> "$cache_file"
done
printf 'done\n'
else
msg 'Not nuking/creating new clipmenu files'
fi
msg 'Running modified clipmenu'
time /tmp/clipmenu
(( TIME_ONLY )) && exit 0
msg 'Displaying perf data'
# modified from http://stackoverflow.com/a/20855353/945780
paste <(
while read -r tim ;do
[ -z "$last" ] && last=${tim//.} && first=${tim//.}
crt=000000000$((${tim//.}-10#0$last))
ctot=000000000$((${tim//.}-10#0$first))
printf "%12.9f %12.9f\n" ${crt:0:${#crt}-9}.${crt:${#crt}-9} \
${ctot:0:${#ctot}-9}.${ctot:${#ctot}-9}
last=${tim//.}
done < "$tim"
) "$log" | less