List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:edu.ucsf.valelab.saim.calculations.BenchmarkCalculations.java
/** * Compares two methods to calculate the Saim function * The implementation not using Complex numbers appears to be at least * 10 times faster/* w ww.j a va 2 s. c om*/ * @throws Exception */ public void test() throws Exception { long nrRuns = 100000000; double wavelength = 488.0; double nSample = 1.36; double dOx = 500.0; double h = 16.0; double angle = Math.toRadians(0.0); SaimFunction sf = new SaimFunction(wavelength, dOx, nSample, false); Complex rTE = sf.getFresnelTE(0); double f = 4.0 * Math.PI * nSample * Math.cos(angle) / wavelength; double phaseDiff = f * h; // method 1 long startTime = System.nanoTime(); double c = rTE.getReal(); double d = rTE.getImaginary(); for (int i = 0; i < nrRuns; i++) { double val = 1 + 2 * c * Math.cos(phaseDiff) - 2 * d * Math.sin(phaseDiff) + c * c + d * d; } long endTime = System.nanoTime(); long took = endTime - startTime; System.out.println("First method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds"); // method 2 startTime = System.nanoTime(); for (int i = 0; i < nrRuns; i++) { Complex tmp = new Complex(Math.cos(phaseDiff), Math.sin(phaseDiff)); Complex fieldStrength = rTE.multiply(tmp); fieldStrength = fieldStrength.add(1.0); // square of absolute double val = fieldStrength.getReal() * fieldStrength.getReal() + fieldStrength.getImaginary() * fieldStrength.getImaginary(); } endTime = System.nanoTime(); took = endTime - startTime; System.out.println("Second method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds"); }
From source file:org.commonjava.indy.ftest.core.content.SetContentTypeFromUpstreamIfExistsTest.java
@Test public void run() throws Exception { final String content = "This is some content " + System.currentTimeMillis() + "." + System.nanoTime(); final String path = "org/foo/foo-project/1/foo-1.jar"; server.expect("GET", server.formatUrl(STORE, path), (request, response) -> { response.setStatus(200);// w ww . j a va 2 s. c o m response.setHeader("Content-Length", Integer.toString(content.length())); response.setHeader("Content-Type", "application/java-archive; charset=UTF-8"); PrintWriter writer = response.getWriter(); writer.write(content); }); client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding remote", RemoteRepository.class); try (HttpResources httpResources = client.module(IndyRawHttpModule.class).getHttp() .getRaw(client.content().contentPath(remote, STORE, path))) { HttpResponse response = httpResources.getResponse(); String contentType = response.getFirstHeader("Content-Type").getValue(); assertThat(contentType, equalTo("application/java-archive;charset=UTF-8")); } }
From source file:org.commonjava.indy.httprox.AutoCreateRepoAndRetrieveNoCacheFileTest.java
@Test public void run() throws Exception { final String path = "org/foo/bar/1.0/bar-1.0.nocache"; final String content = "This is a test: " + System.nanoTime(); final String testRepo = "test"; final String url = server.formatUrl(testRepo, path); server.expect(url, 200, content);//from w ww. j a v a2s . c om final HttpGet get = new HttpGet(url); CloseableHttpClient client = proxiedHttp(); CloseableHttpResponse response = null; InputStream stream = null; try { response = client.execute(get, proxyContext(USER, PASS)); stream = response.getEntity().getContent(); final String resultingPom = IOUtils.toString(stream); assertThat(resultingPom, notNullValue()); assertThat(resultingPom, equalTo(content)); } finally { IOUtils.closeQuietly(stream); HttpResources.cleanupResources(get, response, client); } final RemoteRepository remoteRepo = this.client.stores().load( new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()), RemoteRepository.class); assertThat(remoteRepo, notNullValue()); assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri())); String pomUrl = this.client.content().contentUrl(remoteRepo.getKey(), testRepo, path) + "?cache-only=true"; System.out.println("pomUrl:: " + pomUrl); HttpHead head = new HttpHead(pomUrl); client = HttpClients.createDefault(); try { response = client.execute(head); assertThat(response.getStatusLine().getStatusCode(), equalTo(404)); } finally { HttpResources.cleanupResources(head, response, client); } }
From source file:com.alibaba.json.test.Bug_0_Test.java
private void f_ali_json() { long startNano = System.nanoTime(); for (int i = 0; i < COUNT; ++i) { com.alibaba.fastjson.JSON.parse(text); }//from w ww .ja v a 2 s. co m long nano = System.nanoTime() - startNano; System.out.println(NumberFormat.getInstance().format(nano)); }
From source file:com.app.util.SearchResultUtil.java
public static void performSearch() throws DatabaseConnectionException, SQLException { long startTime = System.nanoTime(); ExecutorService executor = Executors.newFixedThreadPool(_THREAD_POOL_SIZE); List<Integer> userIds = UserUtil.getUserIds(true); for (int userId : userIds) { SearchResultRunnable searchResultRunnable = new SearchResultRunnable(userId); executor.execute(searchResultRunnable); }/* ww w.j a v a 2 s . co m*/ executor.shutdown(); try { executor.awaitTermination(_THREAD_TIMEOUT_SECONDS, TimeUnit.SECONDS); } catch (InterruptedException ie) { _log.error("The executor encountered an exception", ie); } long endTime = System.nanoTime(); _log.info("Performing searches for {} users took {} milliseconds", userIds.size(), (endTime - startTime) / 1000000); }
From source file:com.longle1.facedetection.TimedAsyncHttpResponseHandler.java
@Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Log.e("RTT", String.format("%.1f", (System.nanoTime() - startTime) / 1e6) + " ms"); String msg = "RTT: " + String.format("%.1f", (System.nanoTime() - startTime) / 1e6) + " ms"; Toast mToast = Toast.makeText(mContext, msg, Toast.LENGTH_SHORT); mToast.setGravity(Gravity.TOP, 0, 0); TextView v = (TextView) mToast.getView().findViewById(android.R.id.message); v.setTextColor(Color.RED);/*from w w w.j a v a 2 s . co m*/ mToast.show(); }
From source file:ch.algotrader.dao.HibernateInitializer.java
@Override @SuppressWarnings("unchecked") public <T extends BaseEntityI> T initializeProxy(BaseEntityI entity, String context, T proxy) { if (proxy instanceof HibernateProxy) { HibernateProxy hibernateProxy = (HibernateProxy) proxy; LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer(); if (initializer.getSession() != null) { long before = System.nanoTime(); proxy = (T) initializer.getImplementation(); MetricsUtil.account(ClassUtils.getShortClassName(entity.getClass()) + context, (before)); } else {//from www.j av a2 s . c om throw new IllegalStateException("no hibernate session available"); } } return proxy; }
From source file:net.openhft.chronicle.logger.log4j1.Log4j1VanillaChroniclePerfTest.java
@Test public void testSingleThreadLogging1() throws IOException { Thread.currentThread().setName("perf-plain-vanilla"); final String testId = "perf-binary-vanilla-chronicle"; final Logger clogger = LoggerFactory.getLogger(testId); final Logger plogger = LoggerFactory.getLogger("perf-plain-vanilla"); final long items = 1000000; warmup(clogger);/*w w w. ja v a 2s. c o m*/ warmup(plogger); for (int s = 64; s <= 1024; s += 64) { final String staticStr = StringUtils.leftPad("", s, 'X'); long cStart1 = System.nanoTime(); for (int i = 1; i <= items; i++) { clogger.info(staticStr); } long cEnd1 = System.nanoTime(); long pStart1 = System.nanoTime(); for (int i = 1; i <= items; i++) { plogger.info(staticStr); } long pEnd1 = System.nanoTime(); System.out.printf( "items=%03d size=%04d => chronology=%.3f ms, chronology-average=%.3f us, plain=%d, plain-average=%.3f us\n", items, staticStr.length(), (cEnd1 - cStart1) / 1e6, (cEnd1 - cStart1) / items / 1e3, (pEnd1 - pStart1), (pEnd1 - pStart1) / items / 1e3); } IOTools.deleteDir(basePath(testId)); }
From source file:com.ss.language.model.gibblda.Dictionary.java
public Dictionary() { dicName = System.nanoTime() + "" + new Random().nextInt(20) + "_"; init(LDACmdOption.curOption.get()); }
From source file:org.eigengo.rsa.text.v100.TextEntity.java
private TextEntityEvent.Ocred ocr(TextEntityCommand.Ocr ocr) { log.info("Performing OCR for {}", ocr.correlationId); return new TextEntityEvent.Ocred(entityId(), ocr.correlationId, ocr.ingestionTimestamp, System.nanoTime(), new String[] { "text" }); }