Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Odd performance difference between -client and -server

Thread view: 
Remon van Vliet - 26 Jun 2005 12:52 GMT
Hello,

I've run into an odd performance difference between the client and the
server VM. I made a few classes for 3D math and such, and here are two
version of a scale method :

public final static RTVector scale(RTVector v, double s) {

 /* Scale vector and return result  */
 return new RTVector(v.x * s, v.y * s, v.z * s);
}

public final static RTVector scale(RTVector r, RTVector v, double s) {

 /* Scale vector */
 r.set(v.x * s, v.y * s, v.z * s);

 /* Return result vector */
 return r;
}

As you can see, one creates a new vector and returns the result, the other
sets the result in a third vector that's passed to the method. The latter
version should be faster since it doesnt create a new object (note that i
made sure the test isnt creating a new object each iteration either). Now,
for the server VM (-server) all works as expected, for 10000000 runs :

option1 : 0.188s
option2 : 0.032s

The client VM however :

option1 : 0.579s
option2 : 9.547s

As you can see the server VM is way faster for this, which is expected
behavior. What is odd to me is that the option where no new objects are
created is actually a factor 20 slower on the client VM. Does anyone have an
explanation for this? Note that the only difference for these tests is the
VM command line argument -client/-server.

Hope someone can shed some light on this,

Remon van Vliet
Skip - 26 Jun 2005 13:18 GMT
> Hello,
>
[quoted text clipped - 36 lines]
> explanation for this? Note that the only difference for these tests is the
> VM command line argument -client/-server.

Welcome to the world of micro-benchmarking.

The JVM is smarter than you think. It might notice that the new Object in
option 1 is never used, and thus eliminating that part of the code,
resulting in doing 'nothing' which is - well - extremely fast. In option 2,
there is no possibility to optimize (say: completely remove) that code for
the JVM, as it is not "never used" as in option 1.

So basicly:
option 1 does nothing
option 2 does what it is supposed to do

Further, the server VM is really really smart, and might notice that in your
micro-benchmark has no result in either case. Thus doing nothing at all.

Could you please show the micro-benchmark code?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.