clipmenu-spmenu/tests/test-perf
Chris Down f22fce7f04 Use a single line cache file
In c7c894a0, a per-selection line-cache was introduced in order to
overcome some of the limitations of clipmenu at the time (for example,
missing duplicate detection). However, now we have all the features we
need to have a single line cache again, and having multiple line caches
has caused more trouble than it is worth.

For example, maintaining CM_MAX_CLIPS globally is extremely cumbersome,
so we don't do it, and CM_MAX_CLIPS is actually acted on per-selection.
We also have had bugs where we perform actions on cache files without
properly consulting other line caches, and while those can be fixed, the
simplest thing to do now is just to go back to having a single line
cache.
2020-03-23 13:00:14 +00:00

92 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
major_version=6
msg() {
printf '>>> %s\n' "$@" >&2
}
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
dir=$CM_DIR/clipmenu.$major_version.$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
#!/usr/bin/env bash
exec 3>&2 2> >(tee "$log" |
sed -u 's/^.*$/now/' |
date -f - +%s.%N > "$tim")
set -x
dmenu() { :; }
xsel() { :; }
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 ))
data=$(
tr -dc 'a-zA-Z0-9' < /dev/urandom |
fold -w "$line_len" |
head -"$num_lines"
)
read -r first_line_raw <<< "$data"
printf -v first_line '%s (%s lines)\n' "$first_line_raw" "$num_lines"
printf '%d %s' "$i" "$first_line" >> "$cache_file"
fn=$dir/$(cksum <<< "$first_line")
printf '%s' "$data" > "$fn"
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