Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import csv
- import pickle
- data = [chr(i) for i in range(65, 65+26)]
- pickled_data = pickle.dumps(data)
- csv_data = ','.join(data)
- def test_pickle():
- with open('sample_data.pkl', 'w') as f:
- f.write(pickled_data)
- loaded_data = []
- with open('sample_data.pkl', 'r') as f:
- loaded_data.extend(pickle.loads(f.read()))
- def test_csv():
- with open('sample_data.csv', 'w') as f:
- csv_writer = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
- csv_writer.writerow(data)
- loaded_data = []
- with open('sample_data.csv', 'r') as f:
- csv_reader = csv.reader(f)
- loaded_data.extend( [row for row in csv_reader] )
- if __name__ == '__main__':
- import timeit
- print("Pickling Time: %s" % timeit.timeit("test_pickle()", setup="from __main__ import test_pickle", number=10000))
- print("CSV Timei: %s" % timeit.timeit("test_csv()", setup="from __main__ import test_csv", number=10000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement