Skip to content

Instantly share code, notes, and snippets.

@sharkdp
Last active October 7, 2017 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharkdp/4bc3e5f5ea9df2f29c02ede50634b16a to your computer and use it in GitHub Desktop.
Save sharkdp/4bc3e5f5ea9df2f29c02ede50634b16a to your computer and use it in GitHub Desktop.
fd benchmark scripts
echo "This script will now ask for your password in order to gain root/sudo"
echo "permissions. These are required to reset the harddisk caches."
echo ""
sudo echo "Okay, acquired superpowers :-)" || exit
base_path="/mnt/daten"
pattern='.*[0-9]\.jpg$'
for _ in $(seq 1 3); do
echo
echo -n "Resetting caches ... "
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
echo "okay"
echo
echo "Timing 'fd':"
time fd -HI --full-path "$pattern" "$base_path" > /dev/null
echo
echo -n "Resetting caches ... "
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
echo "okay"
echo
echo "Timing 'find':"
time find "$base_path" -iregex "$pattern" > /dev/null 2> /dev/null
done
#!/bin/bash
if ! which bench > /dev/null 2>&1; then
echo "'bench' does not seem to be installed."
echo "You can get it here: https://github.com/Gabriel439/bench"
exit 1
fi
base_path="$HOME"
# Warmup run
echo -n "Running warmup ... "
fd --hidden --no-ignore "" "$base_path" > /dev/null
echo "done"
echo
cmd_find="find '$base_path' -iregex '.*[0-9]\.jpg$'"
cmd_find2="find '$base_path' -iname '*[0-9].jpg'"
cmd_fd="fd --hidden --no-ignore '.*[0-9]\.jpg$' '$base_path'"
cmd_fd2="fd '[0-9]\.jpg$' '$base_path'"
# cmd_fd="fd '^warm-cache.sh$' '$base_path'"
# cmd_find="find '$base_path' -iname warm-cache.sh"
rm results.csv
bench --csv results.csv --output index.html "$cmd_find || true" "$cmd_find2 || true" "$cmd_fd" "$cmd_fd2"
eval "$cmd_fd" | sort > /tmp/results.fd
eval "$cmd_find" 2> /dev/null | sort > /tmp/results.find
if diff -q /tmp/results.fd /tmp/results.find > /dev/null; then
echo "Both fd and find found the same $(wc -l /tmp/results.fd) files"
else
echo "Warning: There where differences between the search results of fd and find!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment