large_carray.py 869 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # # Benchmark to check the creation of an array of length > 2**32 (5e9)
  2. import sys
  3. from time import time
  4. import bcolz
  5. if sys.version_info >= (3,0):
  6. long = int
  7. t0 = time()
  8. #cn = bcolz.zeros(5e9, dtype="i1")
  9. cn = bcolz.zeros(5e9, dtype="i1", rootdir='large_carray-bench', mode='w')
  10. print("Creation time:", round(time() - t0, 3))
  11. print("len:", len(cn))
  12. assert len(cn) == int(5e9)
  13. t0 = time()
  14. cn = bcolz.carray(rootdir='large_carray-bench', mode='a')
  15. print("Re-open time:", round(time() - t0, 3))
  16. print("len(cn)", len(cn))
  17. assert len(cn) == int(5e9)
  18. # Now check some accesses
  19. cn[1] = 1
  20. assert cn[1] == 1
  21. cn[int(2e9)] = 2
  22. assert cn[int(2e9)] == 2
  23. cn[long(3e9)] = 3
  24. assert cn[long(3e9)] == 3
  25. cn[-1] = 4
  26. assert cn[-1] == 4
  27. t0 = time()
  28. assert cn.sum() == 10
  29. print("Sum time:", round(time() - t0, 3))
  30. print("str(carray):", str(cn))
  31. print("repr(carray):", repr(cn))