test-perf (1980B)
1#!/usr/bin/env bash 2 3msg() { 4 printf '>>> %s\n' "$@" >&2 5} 6 7dir=$(clipctl cache-dir) 8cache_file=$dir/line_cache 9 10log=$(mktemp) 11tim=$(mktemp) 12clipmenu_shim=$(mktemp) 13num_files=1500 14 15trap 'rm -f -- "$log" "$tim" "$clipmenu_shim"' EXIT 16 17if [[ $0 == /* ]]; then 18 location=${0%/*} 19else 20 location=$PWD/${0#./} 21 location=${location%/*} 22fi 23 24msg 'Setting up edited clipmenu' 25 26cat - "$location/../clipmenu" > /tmp/clipmenu << EOF 27#!/usr/bin/env bash 28 29exec 3>&2 2> >(tee "$log" | 30 sed -u 's/^.*$/now/' | 31 date -f - +%s.%N > "$tim") 32set -x 33 34dmenu() { :; } 35xsel() { :; } 36 37EOF 38 39chmod a+x /tmp/clipmenu 40 41if ! (( NO_RECREATE )); then 42 rm -rf "$dir" 43 mkdir -p "$dir" 44 45 msg "Writing $num_files clipboard files" 46 47 for (( i = 0; i <= num_files; i++ )); do 48 (( i % 100 )) || printf '%s... ' "$i" 49 50 line_len=$(( (RANDOM % 10000) + 1 )) 51 num_lines=$(( (RANDOM % 10) + 1 )) 52 data=$( 53 tr -dc 'a-zA-Z0-9' < /dev/urandom | 54 fold -w "$line_len" | 55 head -"$num_lines" 56 ) 57 read -r first_line_raw <<< "$data" 58 printf -v first_line '%s (%s lines)\n' "$first_line_raw" "$num_lines" 59 printf '%d %s' "$i" "$first_line" >> "$cache_file" 60 fn=$dir/$(cksum <<< "$first_line") 61 printf '%s' "$data" > "$fn" 62 done 63 64 printf 'done\n' 65else 66 msg 'Not nuking/creating new clipmenu files' 67fi 68 69msg 'Running modified clipmenu' 70 71time /tmp/clipmenu 72 73(( TIME_ONLY )) && exit 0 74 75msg 'Displaying perf data' 76 77# modified from http://stackoverflow.com/a/20855353/945780 78paste <( 79 while read -r tim ;do 80 [ -z "$last" ] && last=${tim//.} && first=${tim//.} 81 crt=000000000$((${tim//.}-10#0$last)) 82 ctot=000000000$((${tim//.}-10#0$first)) 83 printf "%12.9f %12.9f\n" ${crt:0:${#crt}-9}.${crt:${#crt}-9} \ 84 ${ctot:0:${#ctot}-9}.${ctot:${#ctot}-9} 85 last=${tim//.} 86 done < "$tim" 87) "$log" | less