java - Which manner of processing two repetative operations will be completed faster? -


generally speaking, there significant differance in processing speeds of these 2 example segments of code, , if so, should complete faster? assume "processa(int)" , "processb(int)" voids common both examples.

for(int x=0;x<1000;x++){     processa(x);     processb(x); } 

or

for(int x=0;x<1000;x++){     processa(x); } for(int x=0;x<1000;x++){     processb(x); } 

i'm looking see if can speed 1 of programs , involves cycling through blocks of data several times , processing differant ways. currantly, runs seperate cycle each processing method, meaning lot of cycles run in total, each cycle little work. thinking rewriting code each cycle incorporates every processing method; in other words, fewer cycles, each cycle has heavier workload.

this intensive rewrite of program stucture. unless give me significant performance boost, won't worth trouble.

the first case faster second case because loop in , of has effect on performance. however, main question should ask this: effect of significance program? if not, should opt clear , readable code.

one thing remember in such case jvm (java virtual machine) whole lot of optimisation, , in case jvm can rid of for-loop , rewrite code 1000 successive calls processa() , processb(). if have 2 loops, jvm can rid of both, making program more optimal first case.

to basic understanding of method calls, cost, , jvm, can read short article:

https://plumbr.eu/blog/how-expensive-is-a-method-call-in-java


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -