Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In [9]: import array
In [10]: import pickle
In [11]: double_array = array.array("i", range(10 ** 6))
...: start_time = time.time()
...: with open("array_temp.bin", "wb") as f:
...: double_array.tofile(f)
...: array_end_time = time.time() - start_time
In [12]: int_list = list(range(10 ** 6))
...: start_time = time.time()
...: with open("list_temp.bin", "wb") as f:
...: pickle.dump(int_list, f)
...: list_end_time = time.time() - start_time
In [13]: print(f"It took {array_end_time} for int_array to complete")
...: print(f"It took {list_end_time} for int_list to complete")
It took 0.006399869918823242 for int_array to complete
It took 0.03600811958312988 for int_list to complete
In [14]: 0.03600811958312988 / 0.006399869918823242
Out[14]: 5.62638304213389
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.