we don't care ns or ms in our tests (which is fine since that's not exactly what we test) but both are wrong, that's all :).
Romain Manni-Bucau Twitter: @rmannibucau Blog: http://rmannibucau.wordpress.com/ LinkedIn: http://fr.linkedin.com/in/rmannibucau Github: https://github.com/rmannibucau 2014-07-15 18:19 GMT+02:00 Jean-Louis Monteiro <[email protected]>: > Not sure to understand your point/msg. > I don't really care about the 10 pages benchmarks and I have no time to > read it. > I only care about the java contract and JVM implementations accordingly. > > It looks out of context here IMHO as we don't care about the absolute > precision, we only care about the difference. > So regarding the test case above, I still agree going with nanoTime is > better than timeMillis. > > The test is wrong btw, it should not compare absolute values but only the > difference. > If there is an interesting outcome, feel free to share, it will be > appreciated I'm sure. > > JLouis > > > > -- > Jean-Louis Monteiro > http://twitter.com/jlouismonteiro > http://www.tomitribe.com > > > On Tue, Jul 15, 2014 at 6:04 PM, Romain Manni-Bucau <[email protected]> > wrote: > >> can't resist: http://shipilev.net/blog/2014/nanotrusting-nanotime/ >> >> >> Romain Manni-Bucau >> Twitter: @rmannibucau >> Blog: http://rmannibucau.wordpress.com/ >> LinkedIn: http://fr.linkedin.com/in/rmannibucau >> Github: https://github.com/rmannibucau >> >> >> 2014-07-15 17:58 GMT+02:00 Jean-Louis Monteiro <[email protected]>: >> > Definitely for measuring delay nanoTime is better and much more accurate >> > than timeMillis especially on non unix machins. >> > >> > >> > >> > -- >> > Jean-Louis Monteiro >> > http://twitter.com/jlouismonteiro >> > http://www.tomitribe.com >> > >> > >> > On Tue, Jul 15, 2014 at 5:51 PM, <[email protected]> wrote: >> > >> >> Author: andygumbrecht >> >> Date: Tue Jul 15 15:51:08 2014 >> >> New Revision: 1610729 >> >> >> >> URL: http://svn.apache.org/r1610729 >> >> Log: >> >> 1ms is quite a long time >> >> >> >> Modified: >> >> >> >> >> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/singleton/AsyncPostContructTest.java >> >> >> >> Modified: >> >> >> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/singleton/AsyncPostContructTest.java >> >> URL: >> >> >> http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/singleton/AsyncPostContructTest.java?rev=1610729&r1=1610728&r2=1610729&view=diff >> >> >> >> >> ============================================================================== >> >> --- >> >> >> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/singleton/AsyncPostContructTest.java >> >> (original) >> >> +++ >> >> >> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/singleton/AsyncPostContructTest.java >> >> Tue Jul 15 15:51:08 2014 >> >> @@ -16,10 +16,12 @@ >> >> */ >> >> package org.apache.openejb.core.singleton; >> >> >> >> +import org.apache.openejb.OpenEJB; >> >> import org.apache.openejb.jee.EnterpriseBean; >> >> import org.apache.openejb.jee.SingletonBean; >> >> import org.apache.openejb.junit.ApplicationComposer; >> >> import org.apache.openejb.testing.Module; >> >> +import org.junit.AfterClass; >> >> import org.junit.Test; >> >> import org.junit.runner.RunWith; >> >> >> >> @@ -38,6 +40,12 @@ import static org.testng.Assert.assertTr >> >> >> >> @RunWith(ApplicationComposer.class) >> >> public class AsyncPostContructTest { >> >> + >> >> + @AfterClass >> >> + public static void afterClass() throws Exception { >> >> + OpenEJB.destroy(); >> >> + } >> >> + >> >> @EJB >> >> private BuildMeAsync buildMeAsync; >> >> >> >> @@ -50,9 +58,9 @@ public class AsyncPostContructTest { >> >> >> >> @Test >> >> public void postConstructShouldEndsBeforeAsyncCall() { >> >> - final long start = buildMeAsync.getStartEnd(); >> >> + final long constructed = buildMeAsync.getStartEnd(); >> >> final long async = buildMeAsync.getAsyncStart(); >> >> - assertTrue(async > start); >> >> + assertTrue(async >= constructed); >> >> assertSame(buildMeAsync.getAsyncInstance(), >> >> buildMeAsync.getAsyncInstance()); >> >> } >> >> >> >> @@ -77,12 +85,12 @@ public class AsyncPostContructTest { >> >> } catch (final InterruptedException e) { >> >> // no-op >> >> } >> >> - startEnd = System.currentTimeMillis(); >> >> + startEnd = System.nanoTime(); >> >> } >> >> >> >> @Asynchronous >> >> public Future<Boolean> async() { >> >> - asyncStart = System.currentTimeMillis(); >> >> + asyncStart = System.nanoTime(); >> >> asyncInstance = this; >> >> return new AsyncResult<Boolean>(true); >> >> } >> >> >> >> >> >> >>
