Last active
August 29, 2015 14:17
-
-
Save toruw/f80b1dc8a712bab03c27 to your computer and use it in GitHub Desktop.
IO Performance comparison
This file contains 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 mmap,time | |
def test_io(): | |
f = open('test.dat','r+b',0) | |
start = time.time() | |
i = 0 | |
while i < 1000000: | |
f.read() | |
i += 1 | |
end = time.time() | |
print("test_io: %s ms" % ((end - start)*1000)) | |
def test_io_all(): | |
f = open('test.dat','r+b',0) | |
start = time.time() | |
f.read(1000000) | |
end = time.time() | |
print("test_io_all: %s ms" % ((end - start)*1000)) | |
def test_mmap(): | |
f = open('test.dat','r+b') | |
m = mmap.mmap(f.fileno(),0) | |
start = time.time() | |
i = 0 | |
while i < 1000000: | |
m.read_byte() | |
i += 1 | |
end = time.time() | |
print("test_mmap: %s ms" % ((end - start)*1000)) | |
def test_mmap_all(): | |
f = open('test.dat','r+b') | |
m = mmap.mmap(f.fileno(),0) | |
start = time.time() | |
m.read(1000000) | |
end = time.time() | |
print("test_mmap_all: %s ms" % ((end - start)*1000)) | |
if __name__ == '__main__': | |
test_io() | |
test_io_all() | |
test_mmap() | |
test_mmap_all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result
test_io: 1734.96699333 ms
test_io_all: 0.364065170288 ms
test_mmap: 186.017990112 ms
test_mmap_all: 0.677824020386 ms