Chronoscope is a Python toolkit designed to measure execution time, sort profiling results by different criteria (e.g., cumulative time, call count), and save the results in a text file for further analysis. This tool is useful for developers who need to optimize Python code by identifying performance bottlenecks.
- Python environment (Python 3.x recommended)
- Access to standard Python libraries such as
cProfile
,pstats
,os
,datetime
, andtime
No specific installation is required as the tool utilizes standard Python libraries. Ensure that your Python environment is set up correctly.
Print the time taken to run a block of code:
def foo():
foo_list = [1, 2, 3]
for _ in range(100000):
len(foo_list)
Profiler.start_timer()
foo()
Profiler.stop_timer()
Use the @Profiler.profile_function()
decorator to profile an entire function:
@Profiler.profile_function()
def bar():
bar_list = [1, 2, 3]
for _ in range(100000):
len(bar_list)
bar()
For manual control over the profiling start and stop:
def baz():
Profiler.start_profiling()
baz_list = [1, 2, 3]
for _ in range(100000):
len(baz_list)
Profiler.stop_profiling()
baz()