List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:net.openhft.chronicle.logger.slf4j.Slf4jIndexedChronicleBinaryLoggerPerfTest.java
@Test public void testSingleThreadLogging1() throws IOException { Thread.currentThread().setName("perf-plain-indexed"); final String testId = "perf-binary-indexed-chronicle"; final Logger clogger = LoggerFactory.getLogger(testId); final long items = 1000000; warmup(clogger);// w w w. ja v a2 s . c om 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(); System.out.printf("items=%03d size=%04d => chronology=%.3f ms, chronology-average=%.3f us\n", items, staticStr.length(), (cEnd1 - cStart1) / 1e6, (cEnd1 - cStart1) / items / 1e3); } ChronicleTools.deleteOnExit(basePath(testId)); }
From source file:CollectionTest.java
public void stop() { stopTime = System.nanoTime(); stopped = true; }
From source file:net.sourceforge.subsonic.dao.AbstractDao.java
protected int update(String sql, Object... args) { long t = System.nanoTime(); int result = getJdbcTemplate().update(sql, args); log(sql, t);/*from w ww . j av a 2s. c o m*/ return result; }
From source file:com.cloudbees.jenkins.plugins.dockerslaves.DockerfileContainerDefinition.java
@Override public String getImage(DockerDriver driver, Launcher.ProcStarter procStarter, TaskListener listener) throws IOException, InterruptedException { if (image != null) return image; String tag = Long.toHexString(System.nanoTime()); final FilePath workspace = procStarter.pwd(); FilePath contextRoot = workspace.child(contextPath); final FilePath pathToContext = contextRoot.child(contextPath); if (!pathToContext.exists()) { throw new IOException(pathToContext.getRemote() + " does not exists."); }/* w ww . ja va2s. c o m*/ final FilePath pathToDockerfile = contextRoot.child(dockerfile); if (!pathToDockerfile.exists()) { throw new IOException(pathToContext.getRemote() + " does not exists."); } final File context = Util.createTempDir(); pathToContext.copyRecursiveTo(new FilePath(context)); pathToDockerfile.copyTo(new FilePath(new File(context, "Dockerfile"))); final Launcher launcher = new Launcher.LocalLauncher(listener); if (driver.buildDockerfile(launcher, context.getAbsolutePath(), tag) != 0) { throw new IOException("Failed to build image from Dockerfile " + dockerfile); } Util.deleteRecursive(context); this.image = tag; return tag; }
From source file:com.espertech.esper.regression.client.TestThreadedConfigRoute.java
public void testOp() throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); config.getEngineDefaults().getThreading().setInternalTimerEnabled(true); config.getEngineDefaults().getExpression().setUdfCache(false); config.getEngineDefaults().getThreading().setThreadPoolRouteExec(true); config.getEngineDefaults().getThreading().setThreadPoolRouteExecNumThreads(5); config.addEventType("SupportBean", SupportBean.class); config.addImport(SupportStaticMethodLib.class.getName()); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize();// w ww . j a v a2s . c o m log.debug("Creating statements"); int countStatements = 100; SupportListenerTimerHRes listener = new SupportListenerTimerHRes(); for (int i = 0; i < countStatements; i++) { EPStatement stmt = epService.getEPAdministrator() .createEPL("select SupportStaticMethodLib.sleep(10) from SupportBean"); stmt.addListener(listener); } log.info("Sending trigger event"); long start = System.nanoTime(); epService.getEPRuntime().sendEvent(new SupportBean()); long end = System.nanoTime(); long delta = (end - start) / 1000000; assertTrue("Delta is " + delta, delta < 100); Thread.sleep(2000); assertEquals(100, listener.getNewEvents().size()); listener.getNewEvents().clear(); // destroy all statements epService.getEPAdministrator().destroyAllStatements(); EPStatement stmt = epService.getEPAdministrator() .createEPL("select SupportStaticMethodLib.sleep(10) from SupportBean, SupportBean"); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean()); Thread.sleep(100); assertEquals(1, listener.getNewEvents().size()); epService.destroy(); }
From source file:dialog.DialogFunctionUser.java
private void actionAddUserNoController() { if (!isValidData()) { return;/*w ww. j a va2 s .c o m*/ } if (isExistUsername(tfUsername.getText())) { JOptionPane.showMessageDialog(null, "Username tn ti", "Error", JOptionPane.ERROR_MESSAGE); return; } String username = tfUsername.getText(); String fullname = tfFullname.getText(); String password = new String(tfPassword.getPassword()); password = LibraryString.md5(password); int role = cbRole.getSelectedIndex(); User objUser; if (mAvatar != null) { objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role, new Date(System.currentTimeMillis()), mAvatar.getPath()); String fileName = FilenameUtils.getBaseName(mAvatar.getName()) + "-" + System.nanoTime() + "." + FilenameUtils.getExtension(mAvatar.getName()); Path source = Paths.get(mAvatar.toURI()); Path destination = Paths.get("files/" + fileName); try { Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING); } catch (IOException ex) { Logger.getLogger(DialogFunctionRoom.class.getName()).log(Level.SEVERE, null, ex); } } else { objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role, new Date(System.currentTimeMillis()), ""); } if ((new ModelUser()).addItem(objUser)) { ImageIcon icon = new ImageIcon(getClass().getResource("/images/ic_success.png")); JOptionPane.showMessageDialog(this.getParent(), "Thm thnh cng", "Success", JOptionPane.INFORMATION_MESSAGE, icon); } else { JOptionPane.showMessageDialog(this.getParent(), "Thm tht bi", "Fail", JOptionPane.ERROR_MESSAGE); } this.dispose(); }
From source file:com.aef.TicketGeneratorImpl.java
public void addToTicketQueue(TicketBatch ticketBatch) { long startTime = 0L; ticketBatchSendCount.incrementAndGet(); // we're gonna let Redis do the serialization.. if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Adding to queue: %s", ticketBatch)); startTime = System.nanoTime(); }/*from w w w . ja v a 2s. co m*/ ticketQueue.add(ticketBatch); if (LOGGER.isDebugEnabled()) { long elapsed = System.nanoTime() - startTime; LOGGER.debug(String.format("Time to add to queue: %s", DurationFormatUtils.formatDurationHMS(elapsed / 1000000))); } }
From source file:com.longle1.facedetection.TimedAsyncHttpResponseHandler.java
@Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { Log.i("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); mToast.show();//from ww w. j a v a2s .c om }
From source file:com.twosigma.beakerx.kernel.magic.command.functionality.TimeMagicCommand.java
public MagicCommandOutput time(String codeToExecute, Message message, int executionCount, boolean showResult) { CompletableFuture<TimeMeasureData> compileTime = new CompletableFuture<>(); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); long currentThreadId = Thread.currentThread().getId(); Long startWallTime = System.nanoTime(); Long startCpuTotalTime = threadMXBean.getCurrentThreadCpuTime(); Long startUserTime = threadMXBean.getCurrentThreadUserTime(); SimpleEvaluationObject simpleEvaluationObject = createSimpleEvaluationObject(codeToExecute, kernel, message, executionCount);/*from w ww . j a va2 s . c o m*/ if (!showResult) { simpleEvaluationObject.noResult(); } TryResult either = kernel.executeCode(codeToExecute, simpleEvaluationObject); Long endWallTime = System.nanoTime(); Long endCpuTotalTime = threadMXBean.getThreadCpuTime(currentThreadId); Long endUserTime = threadMXBean.getThreadUserTime(currentThreadId); compileTime.complete(new TimeMeasureData(endCpuTotalTime - startCpuTotalTime, endUserTime - startUserTime, endWallTime - startWallTime)); String messageInfo = "CPU times: user %s, sys: %s, total: %s \nWall Time: %s\n"; try { TimeMeasureData timeMeasuredData = compileTime.get(); return new MagicCommandOutput(MagicCommandOutput.Status.OK, String.format(messageInfo, format(timeMeasuredData.getCpuUserTime()), format(timeMeasuredData.getCpuTotalTime() - timeMeasuredData.getCpuUserTime()), format(timeMeasuredData.getCpuTotalTime()), format(timeMeasuredData.getWallTime())), either, simpleEvaluationObject); } catch (InterruptedException | ExecutionException e) { return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "There occurs problem during measuring time for your statement."); } }
From source file:com.snaker.RecognizerManager.java
public String recognize(String url, byte[] image, boolean manual) { String result = null;/*from ww w . j a va 2s . c om*/ if (ocr != null && !manual) { try { result = ocr.recognize(image); } catch (OCRException e) { logger.error("recognize failed", e); } } if (result == null || result.isEmpty()) { RecognizeItem item = new RecognizeItem(); item.id = System.nanoTime(); item.url = url; item.image = image; item.completed = false; synchronized (items) { items.add(item); } synchronized (item) { while (!item.completed) { try { item.wait(); } catch (InterruptedException e) { logger.error("wait error", e); } } } result = item.result; } return result; }