Sunday 20 November 2011

real example of ...which loop is better "for or while" in performance .

hello friends its morning in india , so very good morning to you and thanks to god for providing me a great life .

when i am dealing with " which loop is better for or  while in performance " i found some difficulties but after every stairs surely you get one step closer to your destiny . so lets start with the program but before this here i use a method " System.nanoTime() " which help me the most in finding the difference between for and while .




now these three methods are used like this .

image : 1 --

image : 2 --




here we find the actual time after initialization loop means for ( int i = 0 ; i < 10 ; i++ ) ; so from this program i  found some key points related to performance of loop . these points are following .

1 . the loop which holds the property of initializing takes more time than the other loop which holds the property of only iteration .

2. and after one iteration the loop which holds the property of initialization and the loop which holds the property of only iteration takes nearly equal time 

3. after 37 tries with the help of do-while loop , both loop takes nearly half time of its initialization time .

so if you want to test this program in real machine than please switch to p-2 or p-3 processors because i am using i-3 and finding the accurate result in this machine is very hard for me . so best of luck and the whole program is added ...



No comments: