niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » IBM DB2
Very basic performance question
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
Rhino
*nix forums Guru


Joined: 08 Feb 2005
Posts: 449

PostPosted: Thu Feb 24, 2005 11:25 pm    Post subject: Re: Very basic performance question Reply with quote

"Rhino" <rhino1@NOSPAM.sympatico.ca> wrote in message
news:Z1tTd.23664$uO.681321@news20.bellglobal.com...
Quote:
Given a loop like this:

for (int ix=0; ix<myArray.length; ix++) {
System.out.println(ix);
}

or especially this:

for (int ix=0; ix<Math.sqrt(shoeSize)*hairlength/(IQ); ix++) {
System.out.println(ix);
}

[snip]


Oops, sorry, wrong newsgroup!

Rhino
Back to top
Rhino
*nix forums Guru


Joined: 08 Feb 2005
Posts: 449

PostPosted: Thu Feb 24, 2005 10:02 pm    Post subject: Very basic performance question Reply with quote

Given a loop like this:

for (int ix=0; ix<myArray.length; ix++) {
System.out.println(ix);
}

or especially this:

for (int ix=0; ix<Math.sqrt(shoeSize)*hairlength/(IQ); ix++) {
System.out.println(ix);
}

I've always assumed that it made more sense to look up or calculate the
value in the second term of the for loop, rather than make Java look it up
or calculate it, especially for large numbers of iterations of the loop. It
just made no sense to do the same calculation or lookup a thousand or a
million times; it seemed a lot more reasonable to do the calculation or
lookup ONCE, store the value in a variable, and then plug the variable into
the for loop, like this:

int loopController = Math.sqrt(shoeSize)*hairlength/(IQ);
for (int ix=0; ix<loopController; ix++) {
System.out.println(ix);
}

Is my reasoning sound or does Java have "tricks" (optimizations) that make
it more sensible to leave the lookup or calculation in the loop, this
avoiding the need to create the variable that controls the loop?

I've been wondering about that for a while and am finally getting around to
asking ;-)

I realize that I could set up a benchmark to find out for sure but I'm
betting that the answer is already well-known so I'd rather ask here and
save myself the work ;-)

--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 2:10 am | All times are GMT
navigation Forum index » Databases » IBM DB2
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Newbie question: How to forward a domain to a mailbox? leei Postfix 0 Fri Aug 24, 2007 4:55 pm
No new posts configuration question for httpd Karl Wang Apache 1 Fri Jul 21, 2006 2:10 pm
No new posts nim problem/question Ron AIX 0 Fri Jul 21, 2006 1:57 pm
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am
No new posts Performance and Consistency ?? likun.navipal@gmail.com Berkeley DB 4 Fri Jul 21, 2006 4:24 am

Myspace Graphics | Watch Anime Free Online | Credit Score | Best Credit Cards | Debt Consolidation
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2190s ][ Queries: 20 (0.1049s) ][ GZIP on - Debug on ]