Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can it be possible that assigning zero to a variable takes more time than a For loop with a million iteration?

I am getting a strange output because of profiling my code. For the main calculation of code it correctly shows that more that 70% of time has been spent on those parts but there are some other interesting points. The following line takes %5.8

int counter = 0 ; // %5.8 of total time

and the following For loop has less time consumption (nx = 800 & ny=800)! How this is possible? Picture of the profiler result was attached. enter image description here

like image 958
Mehdi Avatar asked Aug 08 '14 03:08

Mehdi


1 Answers

Better way to test is to attach the profiler but don't start it yet. (This looks like VS profiler which I know will do this.) Run the code, then start the profiler and run it again (or multiple times). This will give you a much better picture of what the code is doing (unless you're TRYING to measure start-up performance).

like image 101
Kyle W Avatar answered Oct 07 '22 22:10

Kyle W