Last active
August 29, 2024 20:57
-
-
Save cornzz/cd978275f41f4d0b5164b989e99937b6 to your computer and use it in GitHub Desktop.
Benchmark read/write speed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to display usage | |
usage() { | |
echo "Usage: $0 --read|--write -t <target_directory>" | |
exit 1 | |
} | |
# Check if at least two arguments are provided | |
if [ "$#" -lt 2 ]; then | |
usage | |
fi | |
# Parse the arguments | |
MODE="" | |
TARGET_DIR="" | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
--read) MODE="read"; shift ;; | |
--write) MODE="write"; shift ;; | |
-t) TARGET_DIR="$2"; shift 2 ;; | |
*) echo "Unknown parameter: $1"; usage ;; | |
esac | |
done | |
# Check if MODE and TARGET_DIR are set | |
if [[ -z "$MODE" || -z "$TARGET_DIR" ]]; then | |
usage | |
fi | |
# Perform the benchmark | |
if [[ "$MODE" == "write" ]]; then | |
echo "Benchmarking write speed in $TARGET_DIR..." | |
dd if=/dev/zero of="$TARGET_DIR"/testfile bs=1M count=1024 conv=fdatasync | |
elif [[ "$MODE" == "read" ]]; then | |
sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches" | |
echo "Benchmarking read speed in $TARGET_DIR..." | |
dd if="$TARGET_DIR"/testfile of=/dev/null bs=1M count=1024 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment