Profile Total time vs timeit
Mostrar comentarios más antiguos
I am studying the efficience of my code and to do that I was measuring the time spent to run the code. But when I use the function timeit to measure it the anwser is 0.15s and when I use the profile the total time is 0.5s. I dont know why the difference in time by measuring it those functions. Anoyone could help me to understand that?
3 comentarios
Bjorn Gustavsson
el 13 de Oct. de 2022
Once uppon a time my guess would've been that it had something to do with the just-in-time compilation-optimization, because then there were some steps that were not used when profiling the code. Now I'm not sure that is an issue, and it seems to be a bit much to explain with timing-related overhead. It might also have to do with the total system-load of your computer, I can see that type of variations if my computer runs hot and starts to swap much to disk.
But, a question to you is: does this difference matter for this task? I've found the profiler suitable to reveal bottle-necks in my code rather effectively.
Augusto Perboni
el 25 de Oct. de 2022
Bruno Luong
el 25 de Oct. de 2022
Profiler is like a measurement device and your code is like a particle in quantum mechanic: you measure it then you perturb it.
Respuestas (1)
The profiler disables (at least parts of) the JIT, the just in time optimization. This happens, because the JIT can reorder commands, if it improves the speed. But then the profiler cannot correlate the processed command with the code lines anymore. This means, that the detailed profiling impedes the processing speed and this is, what the profiler should observe. What a pity.
If the bottleneck is a simple loop with elementary commands, the JIT acceleration can be strong. Then a bottleneck found by the profiler must not be a bottleneck in the real processing.
timeit and tic/toc are less smart und more accurate to compare runtimes between different versions of a code.
Categorías
Más información sobre Performance and Memory en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!