tools.py 691 B

1234567891011121314151617181920212223242526272829
  1. import time
  2. def count(testFn, items):
  3. s = 0
  4. for x in items:
  5. if testFn(x):
  6. s += 1
  7. return s
  8. class Timing:
  9. def __init__(self, name="Duration"):
  10. self.name = name
  11. self.tStart = time.process_time()
  12. self.tStepStart = self.tStart
  13. def step(self, message=""):
  14. now = time.process_time()
  15. duration = now - self.tStart
  16. durationStep = now - self.tStepStart
  17. self.tStepStart = now
  18. if message == "":
  19. print(f"{self.name}: {durationStep:0.5f} / {duration:0.3f}s")
  20. else:
  21. print(f"{self.name} ({message}): {durationStep:0.5f} / {duration:0.3f}s")
  22. return duration