From 7987dd1757a93dad8d706d533f5026cc6037fd49 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Fri, 6 Jan 2017 10:48:02 +0000 Subject: [PATCH] Add test-perf script --- test/test-perf | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 test/test-perf diff --git a/test/test-perf b/test/test-perf new file mode 100755 index 0000000..098d396 --- /dev/null +++ b/test/test-perf @@ -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