Skip to content

Commit

Permalink
add hyperfine
Browse files Browse the repository at this point in the history
  • Loading branch information
Himasnhu-AT committed Dec 10, 2024
1 parent 8b0194b commit e3392f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 72 deletions.
66 changes: 9 additions & 57 deletions bench.sh
Original file line number Diff line number Diff line change
@@ -1,63 +1,15 @@
#!/bin/bash

# Function to run a command and measure its time
measure_time() {
local cmd=$1
local output_file=$2

{ time $cmd; } 2> $output_file
}

# Function to extract time from the output file
extract_time() {
local output_file=$1
grep "real" $output_file | awk '{print $2}'
}

# Ensure the frm binary is built
cargo build --release

# Generate test data
bash test_data_gen.sh

# Measure time for rm -rf
measure_time "rm -rf ./test_data" "rm_time.txt"
rm_time=$(extract_time "rm_time.txt")

# Regenerate test data
bash test_data_gen.sh

# Measure time for frm
measure_time "./target/release/frm ./test_data" "frm_time.txt"
frm_time=$(extract_time "frm_time.txt")

# Create performance.md file
cat <<EOL > performance.md
# Performance Benchmark
## Results
| Command | Time (s) |
|---------|----------|
| rm -rf | $rm_time |
| frm | $frm_time |
## Conclusion
The table above shows the time taken by each command to delete the test data directory. The \`frm\` command is compared against the traditional \`rm -rf\` command.
EOL

# Clean up
rm rm_time.txt frm_time.txt

# hyperfine --warmup 3 --export-markdown performance.md \
# --prepare 'bash test_data_gen.sh && sleep 2' \
# 'rm -rf ./test_data' \
# './target/release/frm ./test_data'

clear
echo "| Command | Time (s) |"
echo "|---------|----------|"
echo "| rm -rf | $rm_time |"
echo "| frm | $frm_time |"
echo ""
echo ""
echo ""
hyperfine --export-markdown performance.md \
--prepare 'bash test_data_gen.sh && sleep 2' \
'rm -rf ./test_data' \
'./target/release/frm ./test_data'

echo "Benchmarking complete. Results stored in performance.md."
rm -rf ./test_data
12 changes: 0 additions & 12 deletions performance.md
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
# Performance Benchmark

## Results

| Command | Time (s) |
| ------- | -------- |
| rm -rf | 0m0.285s |
| frm | 0m0.276s |

## Conclusion

The table above shows the time taken by each command to delete the test data directory. The `frm` command is compared against the traditional `rm -rf` command.
6 changes: 3 additions & 3 deletions test_data_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ create_random_files_and_dirs() {

# Main script
BASE_DIR="./test_data"
NUM_DIRS=40
NUM_FILES=900
DEPTH=4
NUM_DIRS=50
NUM_FILES=10000
DEPTH=10
SEED="fixed_seed"

# Create base directory if it doesn't exist
Expand Down

0 comments on commit e3392f9

Please sign in to comment.