List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:com.noelios.restlet.ext.oauth.MemoryOAuthProvider.java
@Override public void generateRequestToken(OAuthAccessor accessor) { // generate oauth_token and oauth_secret final String consumer_key = (String) accessor.consumer.getProperty("name"); // generate token and secret based on consumer_key // for now use md5 of name + current time as token final String token_data = consumer_key + System.nanoTime(); final String token = DigestUtils.md5Hex(token_data); // for now use md5 of name + current time + token as secret final String secret_data = consumer_key + System.nanoTime() + token; final String secret = DigestUtils.md5Hex(secret_data); accessor.requestToken = token;//from w w w .j a v a 2 s.co m accessor.tokenSecret = secret; accessor.accessToken = null; Context.getCurrentLogger().fine("Adding request token " + accessor); // add to the local cache this.tokens.add(accessor); }
From source file:com.payu.ratel.proxy.monitoring.ServiceInvocationHandler.java
private void publishResponseEvent(ServiceCallResult serviceResult, ProcessContext processCtx, ServiceCallInput input) {// www .ja v a 2 s. c om ServiceInstanceResponseEvent responseEvent = new ServiceInstanceResponseEvent(processCtx, System.nanoTime(), input, serviceResult); for (ServiceInstanceCallListener listener : serviceListeners) { listener.serviceInstanceResponded(responseEvent); } }
From source file:net.carinae.dev.async.TasksIntegrationTest.java
/** * Schedules a simple task for 10 seconds in the future and waits for 5 * minutes for it to be executed.//from w w w . j av a 2 s.c o m */ @Test public void testScheduledSimpleTask() throws InterruptedException { String data = "" + System.nanoTime(); scheduleSimpleTask(data); // Now, try to read from the database int tries = 0; while (tries < 300 && pollDummyEntity(data)) { Thread.sleep(1000); // 1 second tries++; } Assert.assertTrue("Scheduled task didn't execute in 5 minutes time", tries < 300); }
From source file:com.widowcrawler.terminator.parse.ParserTest.java
@Test(timeout = 1000) public void parse_validRobotsTxtLarge_parsesFile() throws Exception { InputStream inputStream = new FileInputStream("src/test/resources/example_robots.txt"); Parser parser = new Parser(inputStream); long start = System.nanoTime(); parser.parse();/*www. j a v a2s . c om*/ long duration = System.nanoTime() - start; System.out.println("Duration: " + duration); }
From source file:com.twitter.common.inject.TimedInterceptor.java
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { // TODO(John Sirois): consider including a SlidingRate tracking thrown exceptions SlidingStats stat = stats.get(methodInvocation.getMethod()); long start = System.nanoTime(); try {// w w w. j a va 2 s .c om return methodInvocation.proceed(); } finally { stat.accumulate(System.nanoTime() - start); } }
From source file:ru.jts_dev.gameserver.parser.data.npc.NpcDatasHolder.java
@PostConstruct private void parse() throws IOException { log.info("Loading data file: npcdata.txt"); final Resource file = context.getResource("scripts/npcdata.txt"); try (InputStream is = file.getInputStream()) { final ANTLRInputStream input = new ANTLRInputStream(is); final NpcDatasLexer lexer = new NpcDatasLexer(input); final CommonTokenStream tokens = new CommonTokenStream(lexer); final NpcDatasParser parser = new NpcDatasParser(tokens); //parser.getInterpreter().setPredictionMode(PredictionMode.SLL); //parser.setErrorHandler(new BailErrorStrategy()); //parser.setProfile(false); long start = System.nanoTime(); final ParseTree tree = parser.file(); log.info("ParseTime: " + (System.nanoTime() - start) / 1_000_000); final ParseTreeWalker walker = new ParseTreeWalker(); start = System.nanoTime(); walker.walk(this, tree); log.info("WalkTime: " + (System.nanoTime() - start) / 1_000_000); }/* w w w . j av a 2 s .co m*/ }
From source file:com.alibaba.jstorm.ui.model.pages.LogPage.java
private void init() throws Exception { long start = System.nanoTime(); try {// www . j a v a 2s. com event = new LogPage.Event(paramMap); conf = getNimbusConf(); // proxy call queryLog(event); } catch (Exception e) { LOG.error(e.getMessage(), e); throw e; } finally { long end = System.nanoTime(); UIMetrics.updateHistorgram(this.getClass().getSimpleName(), (end - start) / 1000000.0d); } }
From source file:me.oriley.crate.CrateGenerator.java
public void buildCrate() { long startNanos = System.nanoTime(); File variantDir = new File(mVariantAssetDir); if (!variantDir.exists() || !variantDir.isDirectory()) { log("Asset directory does not exist, aborting"); return;/*from w w w. j a v a 2 s. c o m*/ } try { brewJava(variantDir, mVariantAssetDir, PACKAGE_NAME).writeTo(new File(mBaseOutputDir)); } catch (IOException e) { logError("Failed to generate java", e, true); } long lengthMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos); log("Time to build was " + lengthMillis + "ms"); }
From source file:SimpleTimer.java
public SimpleTimer() { timeToWait = -1; startTime = System.nanoTime(); }
From source file:com.jsuper.compiler.cli.SuperCommand.java
/** * Run the command line with a specified list of arguments. * * @param args The command line arguments for the compiler. * @return The result to exit the operating system process. */// w w w . ja v a 2 s .c o m private ProcessResult run(String[] args) { if (args.length == 0) { showUsage(); return ProcessResult.SUCCESS; } CompilerConfiguration config = new CompilerConfiguration(); int sourcesIndex = 0; for (int i = 0; i != args.length; ++i) { String argument = args[i]; if (argument.startsWith("-")) { if (argument.equals("--version") || argument.equals("-v")) { showVersion(); } else if (argument.equals("--verbose")) { // TODO showVersion(); } else if (argument.equals("--classpath")) { // TODO showVersion(); } else if (argument.equals("--bootclasspath")) { // TODO showVersion(); } else if (argument.equals("--help") || argument.equals("-h")) { // TODO showUsage(); } else { throw new SuperCommandException("Unknown option: " + argument); } sourcesIndex = i + 1; } } if (sourcesIndex == args.length) { outputStream.println("superc: No files to compile."); return ProcessResult.SUCCESS; } long startTime = System.nanoTime(); SuperCompiler compiler = new SuperCompiler(); CompilerResult results = compiler.compile(config); for (ErrorMessage message : results.getErrorHandler().getErrors()) { errorStream.println(); String filename = message.getLocation().getFilePath(); if (filename != null) { errorStream.println(new File(filename).getAbsolutePath()); } else { errorStream.println("Unknown source"); } if (message.getLocation().getLine() > 0) { errorStream.println(" ("); errorStream.println(message.getLocation().getLine()); if (message.getLocation().getColumn() > 0) { errorStream.println(", "); errorStream.println(message.getLocation().getColumn()); } errorStream.println(")"); } switch (message.getLevel()) { case ERROR: errorStream.println(" error "); break; case WARNING: errorStream.println(" warning "); break; default: throw new IllegalStateException(); } errorStream.println(message.getErrorCode()); errorStream.println(": "); errorStream.println(message.getMessage()); } if (results.getErrorHandler().getErrors().isEmpty()) { try { for (Map.Entry<String, byte[]> e : results.getClassFiles().entrySet()) { String fileName = e.getKey().replace('.', '/') + ".class"; File file = new File(config.getOutputDirectory(), fileName); File dir = file.getParentFile(); if (!dir.exists()) { dir.mkdirs(); } OutputStream classFileOutput = null; try { classFileOutput = new FileOutputStream(file); classFileOutput.write(e.getValue()); } catch (Exception ex) { errorStream.println(String.format("Error writing file ''{0}''", fileName)); throw ex; } finally { IOUtils.closeQuietly(classFileOutput); } } long endTime = System.nanoTime(); String seconds = String.format("%.2f", (endTime - startTime) / 1e9); int totalFiles = results.getClassFiles().size(); outputStream.println( String.format("{0} class(es) successfully generated in {1}s", totalFiles, seconds)); } catch (Exception ex) { errorStream.println("Error writting generated files."); ex.printStackTrace(); } return ProcessResult.SUCCESS; } else { outputStream.println("Compilation failed."); return ProcessResult.FAILURE; } }