Skip to content

Instantly share code, notes, and snippets.

@wavyx
Last active March 29, 2019 04:57
Show Gist options
  • Save wavyx/dd03ad836e1efc003a18ed485ba551e7 to your computer and use it in GitHub Desktop.
Save wavyx/dd03ad836e1efc003a18ed485ba551e7 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# https://unix.stackexchange.com/questions/28756/what-is-the-most-high-performance-linux-filesystem-for-storing-a-lot-of-small-fi?newreg=f9ac548e5fbd4a00bf3a3318a831543e
# https://www.dropbox.com/s/viba8rzdq6uegsq/bench.py?dl=0
#
# or check https://support.binarylane.com.au/support/solutions/articles/1000055889-how-to-benchmark-disk-i-o
# ./fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75
filecount = 300000
filesize = 1024
import random, time
from os import system
flush = "sudo su -c 'sync ; echo 3 > /proc/sys/vm/drop_caches'"
randfile = open("/dev/urandom", "r")
print "\ncreate test folder:"
starttime = time.time()
system("rm -rf test && mkdir test")
print time.time() - starttime
system(flush)
print "\ncreate files:"
starttime = time.time()
for i in xrange(filecount):
rand = randfile.read(int(filesize * 0.5 + filesize * random.random()))
outfile = open("test/" + unicode(i), "w")
outfile.write(rand)
print time.time() - starttime
system(flush)
print "\nrewrite files:"
starttime = time.time()
for i in xrange(int(filecount / 10)):
rand = randfile.read(int(filesize * 0.5 + filesize * random.random()))
outfile = open("test/" + unicode(int(random.random() * filecount)), "w")
outfile.write(rand)
print time.time() - starttime
system(flush)
print "\nread linear:"
starttime = time.time()
for i in xrange(int(filecount / 10)):
infile = open("test/" + unicode(i), "r")
outfile.write(infile.read());
print time.time() - starttime
system(flush)
print "\nread random:"
starttime = time.time()
outfile = open("/dev/null", "w")
for i in xrange(int(filecount / 10)):
infile = open("test/" + unicode(int(random.random() * filecount)), "r")
outfile.write(infile.read());
print time.time() - starttime
system(flush)
print "\ndelete all files:"
starttime = time.time()
system("rm -rf test")
print time.time() - starttime
system(flush)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment