test_find_fuse.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # 测试函数
  3. run_command_test() {
  4. local command=$1
  5. local iterations=$2
  6. local output_file=$3
  7. echo "Testing command: $command with $iterations iterations..."
  8. total_time=0
  9. for ((i=0; i<$iterations; i++)); do
  10. # 使用 /usr/bin/time 来获取更详细的时间信息
  11. start_time=$(date +%s%N)
  12. eval "$command" > /dev/null
  13. end_time=$(date +%s%N)
  14. elapsed=$(( ($end_time - $start_time) / 1000000 )) # 转换为毫秒
  15. total_time=$(echo "$total_time + $elapsed" | bc)
  16. done
  17. average_time=$(echo "$total_time / $iterations" | bc)
  18. echo "Average elapsed time per iteration: $average_time ms" > "$output_file"
  19. }
  20. # 创建一个测试目录和文件
  21. prepare_test_environment() {
  22. local mount_point=$1
  23. local num_files=$2
  24. echo "Preparing test environment in $mount_point with $num_files files..."
  25. mkdir -p "$mount_point"
  26. for ((i=0; i<num_files; i++)); do
  27. touch "$mount_point/test_file_$i.txt"
  28. done
  29. }
  30. # 准备测试环境
  31. prepare_test_environment /home/sf/os/fuses 1000
  32. # 运行测试
  33. run_command_test "find /home/sf/os/fuses -type f" 100 test_results.txt
  34. # 打印结果
  35. cat test_results.txt