speed.cpp 822 B

12345678910111213141516171819202122232425262728293031
  1. "Benchmark some different implementations for cells"
  2. from openpyxl.compat import range
  3. from openpyxl.cell import Cell
  4. from openpyxl.cell.read_only import ReadOnlyCell
  5. from memory_profiler import memory_usage
  6. import time
  7. def standard():
  8. c = Cell(None, "A", "0", None)
  9. def iterative():
  10. c = ReadOnlyCell(None, None, None, 'n')
  11. def dictionary():
  12. c = {'ws':'None', 'col':'A', 'row':0, 'value':1}
  13. if __name__ == '__main__':
  14. initial_use = memory_usage(proc=-1, interval=1)[0]
  15. for fn in (standard, iterative, dictionary):
  16. t = time.time()
  17. container = []
  18. for i in range(1000000):
  19. container.append(fn())
  20. print("{0} {1} MB, {2:.2f}s".format(
  21. fn.func_name,
  22. memory_usage(proc=-1, interval=1)[0] - initial_use,
  23. time.time() - t))