Python Forum
code timer - PyTimer
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code timer - PyTimer
#1
PyTimer is a module that I created meant to make calculating code execution times much easier. Previously, the only real option was to calculate the time before, then after, and subtract the two, and that had to be done for every block of code you were timing. PyTimer allows the time at specific parts to be logged easily, and then the values can all be displayed easily.

An example:

timer = PyTimer()

for run in range(100):
   temp = ""
   for i in range(10000):
       temp += str(i)
   timer.log()

timer.split("Concat W/ Variable")

for run in range(100):
   temp = []
   for i in range(10000):
       temp.append(str(i))
   "".join(temp)
   timer.log()

timer.split("Concat W/ List & .join")
timer.display_averages()
Output:
Concat W/ Variable:    Average (100 runs): 0.0045 s Concat W/ List & .join:    Average (100 runs): 0.0035 s
Some neat features of this add-on are:
  • Functions can be timed using a decorator
  • Strings of code can be evaluated
  • Functions can be timed over multiple iterations
  • The timer supports splitting
Links:
Reply


Messages In This Thread
code timer - PyTimer - by JacobMorris - Dec-13-2016, 04:12 PM
RE: code timer - PyTimer - by Mekire - Dec-13-2016, 04:39 PM
RE: code timer - PyTimer - by JacobMorris - Dec-13-2016, 04:49 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020