Re: Frugal Server Code Pays Off

Nic Ferrier <[email protected]> 13 Oct 2004 00:47:01 +0100
Newsgroups gmane.comp.java.advanced-servlets
Message-ID <[email protected]>
Charles Forsythe <[email protected]> writes:

> Nic Ferrier wrote:
> 
> OK, fine.  I wrote two classes, Foo and Bar that implement equals().  
> Both fulfill the requirement that equals() return false if passed null, 
> but Foo uses an Exception to detect this, while Bar tests for it using 
> equality (See code below).  After called equals(null) 10 times, the 
> execution time was computed.  Here are the averages I measured:
> 
>     Testing Bar.equals(null)
>         Average time: 4ms
> 
>     Testing Foo.equals(null)
>         Average time: 9ms
> 
> This shows that the Foo (Exception-based) equals() took more than twice 
> the time as the equals() in Bar.  

Yep. But that's not really a fair test since comparing to null is one
of the things the JVM does *really* well.

A fairer test would be to examine a complex if.


But I really wasn't trying to claim that there was no cost at all but
that the cost was insignificant compared to the task. And I was
arguing about non-local exits, not if replacments (though I accept I
may not have qualified that correctly in the heat of battle).


> I think this simple test proved the point: Exceptions are not free. 

They are not. But neither are they expensive. Exceptions involve
allocation so clearly there is a cost. But many complex operations
involve allocation. Measured against such operations exceptions can
come out better.


> The conceit that any single server-based operation requires essentially 
> zero time is why J2EE is such a bloated mess. 4ms is an ETERNITY by most 
> "server" standards and yet, that's the time is takes MY server to do 
> something easy. 

I agree that J2EE (and Java these days) is a bloated mess.


> Here are the details about what I ran the test on:
> 
>     VM: TINI VM 1.14
>         http://www.ibutton.com/TINI/index.html
> 
>     HW: DS80C400 @ 29Mhz on a Systronix TStik
>         http://www.tstik.com/

You don't mention what VM you are using. I presume it's Sun's JDK.

 
> As it is, embedded Servlets are churning along pretty well.  My big 
> "Hey! What about embedded Servers" flame is going to be targeted at the 
> TLS Working Group when I get some data collected...

Don't understand this... explain more in a separate thread
please... or wait until the new group.


Nic


------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

Before posting a question, try to find your answer here: 
<http://www.egroups.com/links/advanced-servlets>
Announcements should go to: [email protected]
To Post a message, send it to: [email protected]
To Unsubscribe, send a blank message to: [email protected] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/advanced-servlets/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/