Skip to content

Instantly share code, notes, and snippets.

@AdamGold
Created March 9, 2019 16:27
Show Gist options
  • Save AdamGold/961758c66cdfe92642eabb61d9ce9866 to your computer and use it in GitHub Desktop.
Save AdamGold/961758c66cdfe92642eabb61d9ce9866 to your computer and use it in GitHub Desktop.
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