Dec-13-2016, 04:12 PM
(This post was last modified: Dec-13-2016, 04:12 PM by JacobMorris.)
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:
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