List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:cc.osint.graphd.processes.TestGraphProcess.java
public void message(JSONObject msg) { try {//from ww w . j ava 2 s . c o m JSONObject visited; if (!msg.has("visited")) { visited = new JSONObject(); } else { visited = msg.getJSONObject("visited"); if (visited.has(getContext().getString(Graph.KEY_FIELD))) { return; } } visited.put(getContext().getString(Graph.KEY_FIELD), System.nanoTime()); msg.put("visited", visited); //log(getContext().getString(Graph.KEY_FIELD) + ": msg = " + msg); int maxLen = 9999999; if (msg.has("maxlen")) { maxLen = msg.getInt("maxlen"); } int msgsSent = 0; if (JSONObject.getNames(visited).length < maxLen) { // spread like wildfire! Set<String> rels = null; if (msg.has("via")) { rels = new HashSet<String>(); rels.add(msg.getString("via")); } Set<JSONVertex> neighbors = getGraph().getOutgoingNeighborsOf(getContext(), rels); for (JSONVertex neighbor : neighbors) { String neighborKey = neighbor.getString(Graph.KEY_FIELD); if (visited.has(neighborKey)) { //log(">> already visited " + neighborKey + " at " + visited.getString(neighborKey)); } else { emit(neighborKey, "testGraphProcess", new JSONObject(msg.toString())); msgsSent++; } } } if (msgsSent == 0) { JSONObject visitObj = msg.getJSONObject("visited"); String[] pathKeys = JSONObject.getNames(visitObj); ; String[] pathKeys1 = new String[pathKeys.length]; for (int i = 0; i < pathKeys.length; i++) { pathKeys1[i] = visitObj.getString(pathKeys[i]) + "|" + pathKeys[i]; } Arrays.sort(pathKeys1); String p = ""; for (String pk : pathKeys1) { String pk1 = pk.substring(pk.indexOf("|") + 1); p += " -> " + pk1; } log("ENDPOINT: " + p); } else { //log(getContext().getKey() + " -> " + msgsSent); } } catch (Exception ex) { ex.printStackTrace(); try { log(getContext().getString(Graph.KEY_FIELD) + ": exception: " + ex.getMessage()); } catch (Exception ex1) { ex1.printStackTrace(); } } }
From source file:is.merkor.cli.Main.java
public static List<String> processCommandLine(final CommandLine cmdLine) { String input = null;/*from w w w. ja v a 2 s . c om*/ String output = null; List<String> results = new ArrayList<String>(); if (cmdLine.hasOption("help") || cmdLine.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar MerkOrExtraction.jar", MerkorCommandLineOptions.options); results.add("no message"); } if (cmdLine.hasOption("input")) { input = cmdLine.getOptionValue("input"); } if (cmdLine.hasOption("output")) { output = cmdLine.getOptionValue("output"); } // bin - icenlp tag mapping if (cmdLine.hasOption("bin_mapping")) { if (null == input) results.add("no input given for bin_mapping!"); else { List<String> wordclassList = new ArrayList<String>(); wordclassList.add("noun"); wordclassList.add("adjective"); wordclassList.add("verb"); long start = System.nanoTime(); // process the file (or all files in inputDir) for each wordclass for (String wc : wordclassList) { IceTagsBinTagsMapping mapper = new IceTagsBinTagsMapping(wc); MerkorTokenReader reader = new MerkorTokenReader(mapper); File inputDir = new File(input); if (inputDir.isDirectory()) { File[] files = inputDir.listFiles(); for (int i = 0; i < files.length; i++) { System.out.println("file nr. " + i); if (!files[i].getName().startsWith(".")) reader.readTokensFromFile(files[i].getAbsolutePath()); } } else if (inputDir.isFile()) { reader.readTokensFromFile(inputDir.getAbsolutePath()); } } double elapsedTime = (double) (System.nanoTime() - start) / 1000000000.0; System.out.println("Execution time: " + elapsedTime + " seconds!"); } } // db-population if (cmdLine.hasOption("fill_db")) { String conn = cmdLine.getOptionValue("db_conn"); String name = cmdLine.getOptionValue("db_name"); String password = cmdLine.getOptionValue("password"); if (null == conn || null == name || null == password || null == input) { results.add("connection, name, password and inputfile needed for option -fill_db!"); return results; } long start = System.nanoTime(); DBPopulation db_pop = new DBPopulation(); db_pop.populateDBFromFile(conn, name, password, input); double elapsedTime = (double) (System.nanoTime() - start) / 1000000000.0; System.out.println("Execution time: " + elapsedTime + " seconds!"); } if (cmdLine.hasOption("extract_patterns")) { PatternExtraction extr = new PatternExtraction(); List<String> patterns = new ArrayList<String>(); try { File inputDir = new File(input); if (inputDir.isDirectory()) { File[] dirs = inputDir.listFiles(); for (int i = 0; i < dirs.length; i++) { if (!dirs[i].getName().startsWith(".")) { File[] files = dirs[i].listFiles(); for (int j = 0; j < files.length; j++) { System.out.println("file nr. " + j); if (!files[j].getName().startsWith(".")) { MerkorFile current = new MerkorFile(files[j].getAbsolutePath()); for (String line : current) { extr.processLine(line); patterns = extr.getExtractedPatternsAsStrings(); } } } } } } else { MerkorFile file = new MerkorFile(input); for (String line : file) { extr.processLine(line); patterns = extr.getExtractedPatternsAsStrings(); } } } catch (Exception e) { e.printStackTrace(); } FileCommunicatorWriting.writeListNonAppend(output, patterns); } if (cmdLine.hasOption("merge_patterns")) { String relation = cmdLine.getOptionValue("relation"); String passwd = cmdLine.getOptionValue("password"); PatternMerger extr = new PatternMerger(); List<String> patterns = new ArrayList<String>(); patterns = extr.process(relation, passwd); FileCommunicatorWriting.writeListNonAppend(output, patterns); } if (cmdLine.hasOption("relations2dbstatements")) { Relations2DBStatements lexReader = new Relations2DBStatements(); String directory = "../relationDetectorResults/"; File[] fileList = FileCommunicatorReading.getFileList(directory); for (File file : fileList) { String fName = file.getName(); String relation = fName.substring(0, fName.indexOf('.')); int relId = LexicalRelationType.getTypeId(relation); if (relId > 0) lexReader.processFile(directory + fName, relId); else System.out.println("no relId found for " + relation); } } return results; }
From source file:apiserver.services.pdf.service.ExtractPdfTextCFService.java
public Object execute(Message<?> message) throws ColdFusionException { ExtractTextResult props = (ExtractTextResult) message.getPayload(); try {//from w ww . j ava2s.c om long startTime = System.nanoTime(); Grid grid = verifyGridConnection(); // Get grid-enabled executor service for nodes where attribute 'worker' is defined. ExecutorService exec = getColdFusionExecutor(); Future<StringResult> future = exec .submit(new ExtractTextCallable(props.getFile().getFileBytes(), props.getOptions())); StringResult _result = future.get(defaultTimeout, TimeUnit.SECONDS); props.setResult(_result.getResult()); long endTime = System.nanoTime(); log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total=" + (endTime - startTime) + "ms"); return props; } catch (Exception ge) { throw new RuntimeException(ge); } }
From source file:com.cloudera.oryx.app.serving.als.LoadIT.java
@Ignore("Difficult to assert about time in cross-platform way; run manually") @Test/*from w w w . j a v a 2 s . c o m*/ public void testContainerOverhead() { long startNS = System.nanoTime(); int requests = 10000; for (int i = 0; i < requests; i++) { try { target("/").request().get(LIST_ID_VALUE_TYPE); } catch (NotFoundException nfe) { // continue } } long usecPerRequest = Math.round((System.nanoTime() - startNS) / (requests * 1000.0)); log.info("{} microseconds / request", usecPerRequest); Assert.assertTrue(usecPerRequest < 3000); }
From source file:moxy.ProxyActiveMqTest.java
private void assertWeCanSendAndReceiveAMessageOn(JmsMessagingTemplate jms) { final String queueName = "testQueue-" + System.nanoTime(); final String message = String.valueOf(System.nanoTime()); jms.convertAndSend(queueName, message); RetryableAssertion retryable = new RetryableAssertion() { protected void assertion() { assertEquals(message, jms.receiveAndConvert(queueName, String.class)); }/* w w w . j av a 2 s . com*/ }; retryable.performAssertion(); assertableListener.assertConnectionWasMadeOn(7878); }
From source file:com.webtide.jetty.load.generator.jenkins.LoadGeneratorProcessRunner.java
public void runProcess(TaskListener taskListener, FilePath workspace, Launcher launcher, String jdkName, // Node currentNode, List<Resource.NodeListener> nodeListeners, // List<LoadGenerator.Listener> loadGeneratorListeners, // List<String> args, String jvmExtraArgs, String alpnVersion, // Map<String, String> jdkVersionAlpnBootVersions) throws Exception { Channel channel = null;/*from ww w . ja v a 2s . c o m*/ try { long start = System.nanoTime(); JDK jdk = StringUtils.isEmpty(jdkName) ? // null : Jenkins.getInstance().getJDK(jdkName).forNode(currentNode, taskListener); channel = new LoadGeneratorProcessFactory().buildChannel(taskListener, jdk, workspace, launcher, jvmExtraArgs); // alpn version from jdk if (StringUtils.isEmpty(alpnVersion) && !StringUtils.equals(alpnVersion, "N/A")) { String javaVersion = findJavaVersion(channel, taskListener); alpnVersion = jdkVersionAlpnBootVersions.get(javaVersion); // download alpn jar } channel.call(new LoadCaller(args, nodeListeners, loadGeneratorListeners)); long end = System.nanoTime(); taskListener.getLogger().println("remote LoadGenerator execution done: " // + TimeUnit.NANOSECONDS.toMillis(end - start) // + " ms "); } finally { if (channel != null) { channel.close(); } } }
From source file:com.example.HoneycombFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { chain.doFilter(request, response); return;//from w w w . j a v a 2 s. co m } HttpServletRequest req = (HttpServletRequest) request; long start = System.nanoTime(); try { chain.doFilter(request, response); } finally { long responseTimeNanos = System.nanoTime() - start; Event event = libhoney.newEvent(); event.addField("method", req.getMethod()); event.addField("path", req.getRequestURI()); event.addField("query", req.getQueryString()); Principal principal = req.getUserPrincipal(); if (principal != null) { event.addField("user", principal.getName()); } event.addField("host", req.getRemoteHost()); event.addField("responseTimeNanos", responseTimeNanos); try { event.send(); } catch (HoneyException e) { log.error(e.getMessage(), e); } } }
From source file:biz.c24.io.spring.batch.reader.performance.util.ItemReaderJobRunner.java
/** * Executes the test.//from w w w . jav a 2 s.c o m * Fires up the specified number of threads to invoke read on the C24ItemReader until there * is no more data to read. * Tracks the number of items read and the cumulative processing time. */ public void runJob() { ItemReaderJobRunner.Worker<ComplexDataObject>[] workers = new ItemReaderJobRunner.Worker[numThreads]; C24ItemReader<ComplexDataObject> reader = createReader(); for (int i = 0; i < workers.length; i++) { workers[i] = new ItemReaderJobRunner.Worker<ComplexDataObject>(); workers[i].setReader(reader); workers[i].start(); } recordsProcessed = 0; long startTime = System.nanoTime(); for (int i = 0; i < workers.length; i++) { try { workers[i].join(200000); recordsProcessed += workers[i].getCount(); if (workers[i].getException() != null) { throw new RuntimeException(workers[i].getException()); } } catch (InterruptedException e) { throw new RuntimeException("Interrupted waiting on thread"); } if (workers[i].isAlive()) { throw new RuntimeException("Timed out waiting for thread to complete its work"); } } runTime = System.nanoTime() - startTime; reader.cleanup(); }
From source file:info.simplecloud.scimproxy.compliance.test.WorkingPostTest.java
@Override public List<TestResult> run() { List<TestResult> results = new ArrayList<>(); // simple user User scimUser = new User(); Group scimGroup = new Group(); // full user//w ww . jav a 2 s .c om User scimUserFull = getUser(); long nanoTime = System.nanoTime(); // user scimUser.setUserName("J" + nanoTime); results.add(create("json", scimUser, false)); scimUser.setUserName("Js" + nanoTime); results.add(create("json", scimUser, true)); scimUserFull.setUserName("Jso" + nanoTime); results.add(create("json", scimUserFull, false)); // group scimGroup.setDisplayName("ScimGroupJson"); results.add(create("json", scimGroup, false)); // run same tests but now with XML if (csp.getSpc().hasXmlDataFormat()) { // user scimUser.setUserName("X" + nanoTime); results.add(create("xml", scimUser, false)); scimUser.setUserName("Xm" + nanoTime); results.add(create("xml", scimUser, true)); scimUserFull.setUserName("Xml" + nanoTime); results.add(create("xml", scimUserFull, false)); // group scimGroup.setDisplayName("ScimGroupXml"); results.add(create("xml", scimGroup, false)); } return results; }
From source file:ch.algotrader.util.metric.MetricsUtil.java
/** * print-out all metric values/* w w w. j a va2 s. com*/ */ public static void logMetrics() { if (isMetricsEnabled && LOGGER.isInfoEnabled()) { if (ConfigLocator.instance().getCommonConfig().isSimulation()) { LOGGER.info("TotalDuration: {} millis", (System.nanoTime() - startMillis)); } for (Metric metric : metrics.values()) { LOGGER.info("{}: {} millis {} executions", metric.getName(), metric.getTime(), metric.getExecutions()); } } }