dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

test-perf (2067B)


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