Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 7434BB5DBD7 for ; Mon, 13 Jun 2011 09:11:31 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 90365-05 for ; Mon, 13 Jun 2011 12:11:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.softperience.eu (static-ip-217-118-26-141.inaddr.intergenia.de [217.118.26.141]) by mail.postgresql.org (Postfix) with ESMTP id 2975AB5DBC6 for ; Mon, 13 Jun 2011 09:11:23 -0300 (ADT) Received: from mail.softperience.eu (static-ip-217-118-26-141.inaddr.intergenia.de [217.118.26.141]) by mail.softperience.eu (Postfix) with ESMTPA id 2E9D6C000C2; Mon, 13 Jun 2011 14:11:07 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Mon, 13 Jun 2011 14:11:07 +0200 From: =?UTF-8?Q?Rados=C5=82aw_Smogura?= To: Israel Ben Guilherme Fonseca Cc: Subject: Re: Question about speed: Weird Behavior In-Reply-To: References: <4DF5B7B3.7010708@postnewspapers.com.au> Message-ID: <56264945a293522f5d499649330d3f84@mail.softperience.eu> X-Sender: rsmogura@softperience.eu User-Agent: Roundcube Webmail/0.5.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/28 X-Sequence-Number: 21952 On Mon, 13 Jun 2011 08:31:41 -0300, Israel Ben Guilherme Fonseca wrote: > The actual tests are executed many times, I just tried to make a > simpler test to be easier to understand. > > I executed this code some times to get the average of the result. > > Other point: > > Executing this code 10 times give different averages of executing the > same code in 10 times loop. So the system cache is actually linked to > the same JVM instance? No system cache where PostgreSQL server resides, if you query database for something DB need to read disk, if those data are in cache then it will go faster. Of course whole image is much more complicated. There may be some fluctuations with JIT, as Craig wrote (actually you should take times after 1000 of invocations - if it's client JVM , or change compile threshold in JVM to be sure if JVM doesn't gives you overhead). There may be some GC overhead, you should call System.gc after or before each pass to start with similar environment. As well, some if you connect through TCP/IP this may randomize your results too. Regards, Radek >At each separated invocation the values keep > somewhat constant, differently from one execution with a loop. > > Ill try the "select *" approach in the terminal later. > > 2011/6/13 Craig Ringer > >> 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 youre right on the border of the precision the timers you >> are >> using can offer you. Its hard to be sure as you didnt 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() >> [1] >> >> > Anyway, that speed increases is definitely a good thing, but why >> this >> > happens its 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 > > > > Links: > ------ > [1] > > http://download.oracle.com/javase/1,5.0/docs/api/java/lang/System.html#nanoTime%28%29 > [2] mailto:craig@postnewspapers.com.au