Skip to content

Instantly share code, notes, and snippets.

@guyskk
Created June 10, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guyskk/4e1e1a932e15ae38768a186dc3c2dbee to your computer and use it in GitHub Desktop.
Save guyskk/4e1e1a932e15ae38768a186dc3c2dbee to your computer and use it in GitHub Desktop.
IO performance test
import os
import random
import timeit
def random_content():
return os.urandom(random.randint(1, 10) * 1024)
file = open('test.db', 'wb')
fd = file.fileno()
contents = [random_content() for i in range(10)]
def sequence_write():
for data in contents:
os.write(fd, data)
os.fsync(fd)
def batch_write():
for data in contents:
os.write(fd, data)
os.fsync(fd)
def main():
print(timeit.timeit(sequence_write, number=1000))
print(timeit.timeit(batch_write, number=1000))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment