Created
April 2, 2018 02:24
-
-
Save hankliu5/507623477a1d11fa79751b9d2ff8a361 to your computer and use it in GitHub Desktop.
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 numpy as np | |
import time | |
import sys | |
import csv | |
import mmap | |
ret = [] | |
current_time = time.time() | |
with open(sys.argv[1], 'r') as f: | |
for line in f: | |
floats = map(float, line.split(' ')) | |
ret.append(floats) | |
x = np.asarray(ret) | |
convert_time = time.time() - current_time | |
print('customized function convertion time: {} secs'.format(convert_time)) | |
ret = [] | |
current_time = time.time() | |
with open(sys.argv[1], 'r+b') as f: | |
mm = mmap.mmap(f.fileno(), 0) | |
line = mm.readline() | |
while line != '': | |
ret.append(map(float, line.split(' '))) | |
line = mm.readline() | |
y = np.asarray(ret) | |
convert_time = time.time() - current_time | |
print('mmap convertion time: {} secs'.format(convert_time)) | |
ret = [] | |
current_time = time.time() | |
with open(sys.argv[1], 'r') as f: | |
reader = csv.reader(f, delimiter=' ') | |
for row in reader: | |
floats = map(float, row) | |
ret.append(floats) | |
z = np.asarray(ret) | |
convert_time = time.time() - current_time | |
A = np.load(sys.argv[2]) | |
print('CSV convertion time: {} secs'.format(convert_time)) | |
print('Customized Function Correctness: {}'.format(np.array_equal(x, A))) | |
print('mmap Function Correctness: {}'.format(np.array_equal(y, A))) | |
print('CSV Function Correctness: {}'.format(np.array_equal(z, A))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment