rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 256 forks source link

Add an option for skipping first call of a function #143

Open timabbott opened 5 years ago

timabbott commented 5 years ago

A common situation when profiling is that a piece of code has a high first-call cost (e.g. the first call will do some expensive initialization), but future calls to the piece of code will be fast because they can reuse that initialization. It'd be awesome if there were a way to pass an argument to LineProfiler to skip the first run of a given function for the purposes of the statistics. E.g. syntax like this:

import line_profiler                                                                                                                        
profile = line_profiler.LineProfiler()                                                                                                      

@profile(skip_first_call=True)