btrfs-extract-benchmark.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # !/bin/sh
  2. set -e
  3. # Benchmarks run on a Ubuntu 14.04 VM with 2 cores and 4 GiB of RAM.
  4. # The VM is running on a Macbook Pro with a 3.1 GHz Intel Core i7 processor and
  5. # 16 GB of RAM and an SSD.
  6. # silesia is a directory that can be downloaded from
  7. # http://mattmahoney.net/dc/silesia.html
  8. # ls -l silesia/
  9. # total 203M
  10. # -rwxr-xr-x 1 terrelln 9.8M Apr 12 2002 dickens
  11. # -rwxr-xr-x 1 terrelln 49M May 31 2002 mozilla
  12. # -rwxr-xr-x 1 terrelln 9.6M Mar 20 2003 mr
  13. # -rwxr-xr-x 1 terrelln 32M Apr 2 2002 nci
  14. # -rwxr-xr-x 1 terrelln 5.9M Jul 4 2002 ooffice
  15. # -rwxr-xr-x 1 terrelln 9.7M Apr 11 2002 osdb
  16. # -rwxr-xr-x 1 terrelln 6.4M Apr 2 2002 reymont
  17. # -rwxr-xr-x 1 terrelln 21M Mar 25 2002 samba
  18. # -rwxr-xr-x 1 terrelln 7.0M Mar 24 2002 sao
  19. # -rwxr-xr-x 1 terrelln 40M Mar 25 2002 webster
  20. # -rwxr-xr-x 1 terrelln 8.1M Apr 4 2002 x-ray
  21. # -rwxr-xr-x 1 terrelln 5.1M Nov 30 2000 xml
  22. # $HOME is on a ext4 filesystem
  23. BENCHMARK_FILE="linux-4.11.6.tar"
  24. BENCHMARK_DIR="$HOME/$BENCHMARK_FILE"
  25. # Normalize the environment
  26. sudo umount /mnt/btrfs 2> /dev/null > /dev/null || true
  27. sudo mount -t btrfs $@ /dev/sda3 /mnt/btrfs
  28. sudo rm -rf /mnt/btrfs/*
  29. sync
  30. sudo umount /mnt/btrfs
  31. sudo mount -t btrfs $@ /dev/sda3 /mnt/btrfs
  32. # Run the benchmark
  33. echo "Copy"
  34. time sh -c "sudo cp -r $BENCHMARK_DIR /mnt/btrfs/$BENCHMARK_FILE && sync"
  35. echo "Approximate tarred compression ratio"
  36. printf "%d / %d\n" \
  37. $(df /mnt/btrfs --output=used -B 1 | tail -n 1) \
  38. $(sudo du /mnt/btrfs -b -d 0 | tr '\t' '\n' | head -n 1);
  39. # Unmount and remount to avoid any caching
  40. sudo umount /mnt/btrfs
  41. sudo mount -t btrfs $@ /dev/sda3 /mnt/btrfs
  42. echo "Extract"
  43. time sh -c "sudo tar -C /mnt/btrfs -xf /mnt/btrfs/$BENCHMARK_FILE && sync"
  44. # Remove the tarball, leaving only the extracted data
  45. sudo rm /mnt/btrfs/$BENCHMARK_FILE
  46. # Unmount and remount to avoid any caching
  47. sudo umount /mnt/btrfs
  48. sudo mount -t btrfs $@ /dev/sda3 /mnt/btrfs
  49. echo "Approximate extracted compression ratio"
  50. printf "%d / %d\n" \
  51. $(df /mnt/btrfs --output=used -B 1 | tail -n 1) \
  52. $(sudo du /mnt/btrfs -b -d 0 | tr '\t' '\n' | head -n 1);
  53. echo "Read"
  54. time sudo tar -c /mnt/btrfs 2> /dev/null | wc -c > /dev/null
  55. sudo rm -rf /mnt/btrfs/*
  56. sudo umount /mnt/btrfs
  57. # Run for each of -o compress-force={none, lzo, zlib, zstd} 5 times and take the
  58. # min time and ratio.
  59. # none
  60. # copy: 0.981 s
  61. # extract: 5.501 s
  62. # read: 8.807 s
  63. # tarball ratio: 0.97
  64. # extracted ratio: 0.78
  65. # lzo
  66. # copy: 1.631 s
  67. # extract: 8.458 s
  68. # read: 8.585 s
  69. # tarball ratio: 2.06
  70. # extracted ratio: 1.38
  71. # zlib
  72. # copy: 7.750 s
  73. # extract: 21.544 s
  74. # read: 11.744 s
  75. # tarball ratio : 3.40
  76. # extracted ratio: 1.86
  77. # zstd 1
  78. # copy: 2.579 s
  79. # extract: 11.479 s
  80. # read: 9.389 s
  81. # tarball ratio : 3.57
  82. # extracted ratio: 1.85