Re: Question about speed: Weird Behavior

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Israel Ben Guilherme Fonseca <israel(dot)bgf(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Question about speed: Weird Behavior
Date: 2011-06-13 07:09:39
Message-ID: 4DF5B7B3.7010708@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 13/06/11 11:14, Israel Ben Guilherme Fonseca wrote:

> At every stop, I print the milliseconds occurred between the begin and
> the end of the operation. The results were basically
>
> 1st operation: 0.05 miliseconds
> 2nd operation: 0.1 miliseconds

I suspect you're right on the border of the precision the timers you are
using can offer you. It's hard to be sure as you didn't mention you
platform, CPU, or JDK version.

Try using System.nanoTime() for your timing, and/or (much better) do
many iterations rather than just one to try to smooth out error and jitter.

http://download.oracle.com/javase/1,5.0/docs/api/java/lang/System.html#nanoTime()

> Anyway, that speed increases is definitely a good thing, but why this
> happens it's a mystery for me. The problem is that my benchmark tests
> are influenced with this, cause the order of the tests can influence the
> outcome of the total time.

You really need to tweak your benchmarks to reflect more of a real-world
workload. Timing tiny statements stand-alone will not give you data with
any relationship to what will happen under real load with many such
operations happening concurrently or thousands of them being executed in
rapid sequence.

--
Craig Ringer

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Israel Ben Guilherme Fonseca 2011-06-13 11:31:41 Re: Question about speed: Weird Behavior
Previous Message Radosław Smogura 2011-06-13 05:17:51 Re: Question about speed: Weird Behavior