22
33
44
5+ cd " $( dirname " $0 " ) " || exit
6+
7+
8+
9+ ask_for_sudo () {
10+ echo " This script will now ask for your password in order to gain root/sudo"
11+ echo " permissions. These are required to reset the harddisk caches in between"
12+ echo " benchmark runs."
13+ echo " "
14+
15+ sudo echo " Okay, acquired superpowers :-)" || exit
16+
17+ echo " "
18+ }
19+
20+
21+
22+ export WARMUP_COUNT=5
23+
24+ # command for "cold cache" benchmarks
25+ export RESET_CACHES=" sync; echo 3 | sudo tee /proc/sys/vm/drop_caches"
26+
27+
528TMP_DIR=" ${TMP:-/ tmp} "
629
730llvm_link=https://github.com/llvm/llvm-project
@@ -10,12 +33,10 @@ LLVM="$TMP_DIR/llvm-project"
1033fdf_location=" $TMP_DIR /fdf_test"
1134
1235fdf_repo=https://github.com/alexcu2718/fdf
13-
36+ # shellcheck disable=SC2034
1437SEARCH_ROOT=" $LLVM "
1538
16-
17-
18- alias sort=' sort --parallel=$(nproc)' # speed up sorting speed
39+ EXCLUDE=' paru/clone/.*/pkg|systemd-private|fd.*\.lst$'
1940
2041
2142
2950 :
3051fi
3152
32- # Clone and build fdf if not already installed
53+
3354if [ ! -e " $fdf_location " ]; then
3455 echo " Cloning fdf to $fdf_location ..."
3556 git clone " $fdf_repo " " $fdf_location " > /dev/null
4364fi
4465
4566export PATH=" $fdf_location /target/release:$PATH "
67+
68+ run_warm_benchmark () {
69+ local benchmark_name=" $1 "
70+ local fdf_args=" $2 "
71+ local fd_args=" $3 "
72+ local output_basename=" ${4:- $benchmark_name } "
73+ local skip_diff=" ${5:- 0} "
74+
75+ OUTPUT_DIR=" ./bench_results"
76+ mkdir -p " $OUTPUT_DIR "
77+
78+
79+ local COMMAND_FIND=" fdf $fdf_args "
80+ local COMMAND_FD=" fd $fd_args "
81+
82+
83+ if [[ " $skip_diff " == " 0" ]]; then
84+ # (filter out paru and systemd temporary files (these are protected files so these would be false results anyway))
85+ echo -e " \nGetting accurate file counts..."
86+ fd_count=$( eval " $COMMAND_FD " | grep -vcE " $EXCLUDE " )
87+ fdf_count=$( eval " $COMMAND_FIND " | grep -vcE " $EXCLUDE " )
88+ echo " fd count: $fd_count "
89+ echo " fdf count: $fdf_count "
90+ fi
91+
92+
93+ echo -e " \nRunning benchmarks..."
94+ hyperfine \
95+ --warmup " $WARMUP_COUNT " \
96+ --prepare ' sync; sleep 0.2' \
97+ " $COMMAND_FIND " \
98+ " $COMMAND_FD " \
99+ --export-markdown " $OUTPUT_DIR /results-warm-cache-${benchmark_name} .md"
100+
101+ if [[ " $skip_diff " == " 0" ]]; then
102+ # sorted output lists (filter out paru and systemd files)
103+ eval " $COMMAND_FD " | grep -vE " $EXCLUDE " | sort --parallel=" $( nproc) " > " $OUTPUT_DIR /fd_${output_basename} .lst"
104+ eval " $COMMAND_FIND " | grep -vE " $EXCLUDE " | sort --parallel=" $( nproc) " > " $OUTPUT_DIR /fdf_${output_basename} .lst"
105+
106+ diff -u " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" > " $OUTPUT_DIR /fd_diff_${output_basename} .md"
107+
108+ differences=$( comm -3 " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" | wc -l)
109+ echo " Total lines differing: $differences "
110+
111+ if [[ $differences -gt 0 ]]; then
112+ echo -e " \nFiles only in fd (showing first 10):"
113+ echo -e " \n\n\n THESE FILES ARE USUALLY EXCLUDED DUE PERMISSIONS (fd usually being at /usr/bin/fd )"
114+ comm -23 " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" | head -n 10
115+
116+ echo -e " \nFiles only in fdf (showing first 10):"
117+ comm -13 " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" | head -n 10
118+
119+ echo -e " \nFull diff available in: $( realpath $OUTPUT_DIR /fd_diff_" ${output_basename} " .md) "
120+ else
121+ echo " No differences found in direct execution"
122+ fi
123+
124+ # Report results locations
125+ echo -e " \nBenchmark results saved to $OUTPUT_DIR /results-warm-cache-${benchmark_name} .md"
126+ echo " Diff results saved to $OUTPUT_DIR /fd_diff_${output_basename} .md"
127+ else
128+ echo -e " \nBenchmark results saved to $OUTPUT_DIR /results-warm-cache-${benchmark_name} .md"
129+ fi
130+ }
131+
132+
133+ run_cold_benchmark () {
134+ local benchmark_name=" $1 "
135+ local fdf_args=" $2 "
136+ local fd_args=" $3 "
137+ local output_basename=" ${4:- $benchmark_name } "
138+ local min_runs=" ${5:- 3} "
139+
140+ OUTPUT_DIR=" ./bench_results"
141+ mkdir -p " $OUTPUT_DIR "
142+
143+ local COMMAND_FIND=" fdf $fdf_args "
144+ local COMMAND_FD=" fd $fd_args "
145+
146+ echo -e " \nRunning cold cache benchmarks..."
147+ hyperfine \
148+ --min-runs " $min_runs " \
149+ --prepare " $RESET_CACHES " \
150+ " $COMMAND_FIND " \
151+ " $COMMAND_FD " \
152+ --export-markdown " $OUTPUT_DIR /results-cold-cache-${benchmark_name} .md"
153+
154+
155+
156+ eval " $COMMAND_FD " | grep -vE " $EXCLUDE " | sort --parallel=" $( nproc) " > " $OUTPUT_DIR /fd_${output_basename} .lst"
157+ eval " $COMMAND_FIND " | grep -vE " $EXCLUDE " | sort --parallel=" $( nproc) " > " $OUTPUT_DIR /fdf_${output_basename} .lst"
158+
159+ diff -u " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" > " $OUTPUT_DIR /fd_diff_${output_basename} .md"
160+
161+
162+ differences=$( comm -3 " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" | wc -l)
163+ echo " Total lines differing: $differences "
164+
165+ if [[ $differences -gt 0 ]]; then
166+ echo -e " \nFiles only in fd (showing first 10):"
167+ comm -23 " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" | head -n 10
168+
169+ echo -e " \nFiles only in fdf (showing first 10):"
170+ comm -13 " $OUTPUT_DIR /fd_${output_basename} .lst" " $OUTPUT_DIR /fdf_${output_basename} .lst" | head -n 10
171+
172+ echo -e " \nFull diff available in: $( realpath $OUTPUT_DIR /fd_diff_" ${output_basename} " .md) "
173+ else
174+ echo " No differences found in direct execution"
175+ fi
176+
177+
178+ echo -e " \nBenchmark results saved to $OUTPUT_DIR /results-cold-cache-${benchmark_name} .md"
179+ echo " Diff results saved to $OUTPUT_DIR /fd_diff_${output_basename} .md"
180+ }
0 commit comments