Created
June 10, 2020 15:05
-
-
Save guyskk/4e1e1a932e15ae38768a186dc3c2dbee to your computer and use it in GitHub Desktop.
IO performance test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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