List of usage examples for java.lang System currentTimeMillis
@HotSpotIntrinsicCandidate public static native long currentTimeMillis();
From source file:boa.evaluator.BoaEvaluator.java
public static void main(final String[] args) { final Options options = new Options(); options.addOption("i", "input", true, "input Boa source file (*.boa)"); options.addOption("d", "data", true, "path to local data directory"); options.addOption("o", "output", true, "output directory"); options.getOption("i").setRequired(true); options.getOption("d").setRequired(true); try {/*from w w w . j av a2 s. c om*/ if (args.length == 0) { printHelp(options, null); return; } else { final CommandLine cl = new PosixParser().parse(options, args); if (cl.hasOption('i') && cl.hasOption('d')) { final BoaEvaluator evaluator; try { if (cl.hasOption('o')) { evaluator = new BoaEvaluator(cl.getOptionValue('i'), cl.getOptionValue('d'), cl.getOptionValue('o')); } else { evaluator = new BoaEvaluator(cl.getOptionValue('i'), cl.getOptionValue('d')); } } catch (final IOException e) { System.err.print(e); return; } if (!evaluator.compile()) { System.err.println("Compilation Failed"); return; } final long start = System.currentTimeMillis(); evaluator.evaluate(); final long end = System.currentTimeMillis(); System.out.println("Total Time Taken: " + (end - start)); System.out.println(evaluator.getResults()); } else { printHelp(options, "missing required options: -i <arg> and -d <arg>"); return; } } } catch (final org.apache.commons.cli.ParseException e) { printHelp(options, e.getMessage()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.CdoQueryInvisibleMethodDeclarations.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*w w w . j a v a2s . c om*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryInvisibleMethodDeclarations.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getInvisibleMethodDeclarations(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:edu.duke.cabig.c3pr.webservice.subjectmanagement.client.Client.java
/** * @param args// ww w . jav a 2 s . c o m * @throws Exception */ public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { System.getProperty("context", "applicationContext.xml") }); SubjectManagement client = (SubjectManagement) context.getBean("subjectManagementClient"); QuerySubjectRequest request = new QuerySubjectRequest(); Subject subject = new Subject(); request.setSubject(subject); Person person = new Person(); subject.setEntity(person); // We need to set these to empties in order to pass schema validation on the server side // Need to revisit this issue and perhaps change the XSD: setting fields to empties each time // does not make a lot of sense. person.setAdministrativeGenderCode(new CD()); person.setBirthDate(new TSDateTime()); person.setDeathDate(new TSDateTime()); person.setDeathIndicator(new BL()); person.setEthnicGroupCode(new DSETCD()); person.setMaritalStatusCode(new CD()); person.setName(new DSETENPN()); person.setPostalAddress(new DSETAD()); person.setRaceCode(new DSETCD()); person.setTelecomAddress(new BAGTEL()); // make repeated requests in a loop to cache things, reduce swapping. for (int i = 0; i < 2; i++) { client.querySubject(request); } long start = System.currentTimeMillis(); QuerySubjectResponse response = executeAndGetResponse(client, request); long end = System.currentTimeMillis(); for (Subject subj : response.getSubjects().getItem()) { log.info("Found subject with ID: " + subj.getEntity().getBiologicEntityIdentifier().get(0).getIdentifier().getExtension()); } log.info("Total subjects: " + response.getSubjects().getItem().size()); log.info("Processing time: " + ((end - start) / 1000.0) + " seconds."); }
From source file:io.github.gsteckman.doorcontroller.INA219Util.java
/** * Reads the Current from the INA219 with an I2C address and for a duration specified on the command line. * //from w w w .ja v a 2 s .c om * @param args * Command line arguments. * @throws IOException * If an error occurs reading/writing to the INA219 * @throws ParseException * If the command line arguments could not be parsed. */ public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption("addr", true, "I2C Address"); options.addOption("d", true, "Acquisition duration, in seconds"); options.addOption("bv", false, "Also read bus voltage"); options.addOption("sv", false, "Also read shunt voltage"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); Address addr = Address.ADDR_40; if (cmd.hasOption("addr")) { int opt = Integer.parseInt(cmd.getOptionValue("addr"), 16); Address a = Address.getAddress(opt); if (a != null) { addr = a; } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("INA219Util", options); return; } } int duration = 0; if (cmd.hasOption("d")) { String opt = cmd.getOptionValue("d"); duration = Integer.parseInt(opt); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("INA219Util", options); return; } boolean readBusVoltage = false; if (cmd.hasOption("bv")) { readBusVoltage = true; } boolean readShuntVoltage = false; if (cmd.hasOption("sv")) { readShuntVoltage = true; } INA219 i219 = new INA219(addr, 0.1, 3.2, INA219.Brng.V16, INA219.Pga.GAIN_8, INA219.Adc.BITS_12, INA219.Adc.SAMPLES_128); System.out.printf("Time\tCurrent"); if (readBusVoltage) { System.out.printf("\tBus"); } if (readShuntVoltage) { System.out.printf("\tShunt"); } System.out.printf("\n"); long start = System.currentTimeMillis(); do { try { System.out.printf("%d\t%f", System.currentTimeMillis() - start, i219.getCurrent()); if (readBusVoltage) { System.out.printf("\t%f", i219.getBusVoltage()); } if (readShuntVoltage) { System.out.printf("\t%f", i219.getShuntVoltage()); } System.out.printf("\n"); Thread.sleep(100); } catch (IOException e) { LOG.error("Exception while reading I2C bus", e); } catch (InterruptedException e) { break; } } while (System.currentTimeMillis() - start < duration * 1000); }
From source file:fr.inria.atlanmod.kyanos.benchmarks.CdoQueryThrownExceptionsPerPackage.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*from w w w . j a v a2 s. c o m*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryThrownExceptionsPerPackage.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); HashMap<String, EList<TypeAccess>> map = JavaQueries.getThrownExceptionsPerPackage(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", map.entrySet().size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.CdoQueryClassDeclarationAttributes.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*from ww w .j a v a 2s. c o m*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryClassDeclarationAttributes.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); HashMap<String, EList<NamedElement>> map = JavaQueries.getClassDeclarationAttributes(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", map.entrySet().size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:gpframework.RunExperiment.java
/** * Application's entry point./*from w w w. j a v a2s. c o m*/ * * @param args * @throws ParseException * @throws ParameterException */ public static void main(String[] args) throws ParseException, ParameterException { // Failsafe parameters if (args.length == 0) { args = new String[] { "-f", "LasSortednessFunction", "-n", "5", "-ff", "JoinFactory", "-tf", "SortingElementFactory", "-pf", "SortingProgramFactory", "-s", "SMOGPSelection", "-a", "SMOGP", "-t", "50", "-e", "1000000000", "-mf", "SingleMutationFactory", "-d", "-bn", "other" }; } // Create options Options options = new Options(); setupOptions(options); // Read options from the command line CommandLineParser parser = new PosixParser(); CommandLine cmd; // Print help if parameter requirements are not met try { cmd = parser.parse(options, args); } // If some parameters are missing, print help catch (MissingOptionException e) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar GPFramework \n", options); System.out.println(); System.out.println("Missing parameters: " + e.getMissingOptions()); return; } // Re-initialize PRNG long seed = System.currentTimeMillis(); Utils.random = new Random(seed); // Set the problem size int problemSize = Integer.parseInt(cmd.getOptionValue("n")); // Set debug mode and cluster mode Utils.debug = cmd.hasOption("d"); RunExperiment.cluster = cmd.hasOption("c"); // Initialize fitness function and some factories FitnessFunction fitnessFunction = fromName(cmd.getOptionValue("f"), problemSize); MutationFactory mutationFactory = fromName(cmd.getOptionValue("mf")); Selection selectionCriterion = fromName(cmd.getOptionValue("s")); FunctionFactory functionFactory = fromName(cmd.getOptionValue("ff")); TerminalFactory terminalFactory = fromName(cmd.getOptionValue("tf"), problemSize); ProgramFactory programFactory = fromName(cmd.getOptionValue("pf"), functionFactory, terminalFactory); // Initialize algorithm Algorithm algorithm = fromName(cmd.getOptionValue("a"), mutationFactory, selectionCriterion); algorithm.setParameter("evaluationsBudget", cmd.getOptionValue("e")); algorithm.setParameter("timeBudget", cmd.getOptionValue("t")); // Initialize problem Problem problem = new Problem(programFactory, fitnessFunction); Program solution = algorithm.solve(problem); Utils.debug("Population results: "); Utils.debug(algorithm.getPopulation().toString()); Utils.debug(algorithm.getPopulation().parse()); Map<String, Object> entry = new HashMap<String, Object>(); // Copy algorithm setup for (Object o : options.getRequiredOptions()) { Option option = options.getOption(o.toString()); entry.put(option.getLongOpt(), cmd.getOptionValue(option.getOpt())); } entry.put("seed", seed); // Copy results entry.put("bestProgram", solution.toString()); entry.put("bestSolution", fitnessFunction.normalize(solution)); // Copy all statistics entry.putAll(algorithm.getStatistics()); Utils.debug("Maximum encountered population size: " + algorithm.getStatistics().get("maxPopulationSizeToCompleteFront")); Utils.debug("Maximum encountered tree size: " + algorithm.getStatistics().get("maxProgramComplexityToCompleteFront")); Utils.debug("Solution complexity: " + solution.complexity() + "/" + (2 * problemSize - 1)); }
From source file:scatterplot1k.JFreeScatter.java
/** * Starting point for the demonstration application. * * @param args ignored./*w w w .j a v a2 s . c om*/ */ public static void main(final String[] args) { long start = System.currentTimeMillis(); final JFreeScatter demo = new JFreeScatter("JFreeChart Scatter Plot - 1k", 1000); long create = (System.currentTimeMillis() - start); System.out.println("jfree create = " + create + " ms"); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); long end = (System.currentTimeMillis() - start); System.out.println("jfree show = " + end + " ms"); }
From source file:DruidThroughput.java
@SuppressWarnings("InfiniteLoopStatement") public static void main(String[] args) throws Exception { final int numQueries = QUERIES.length; final Random random = new Random(RANDOM_SEED); final AtomicInteger counter = new AtomicInteger(0); final AtomicLong totalResponseTime = new AtomicLong(0L); final ExecutorService executorService = Executors.newFixedThreadPool(NUM_CLIENTS); for (int i = 0; i < NUM_CLIENTS; i++) { executorService.submit(new Runnable() { @Override//from w w w. j a v a2s.c om public void run() { try (CloseableHttpClient client = HttpClients.createDefault()) { HttpPost post = new HttpPost("http://localhost:8082/druid/v2/?pretty"); post.addHeader("content-type", "application/json"); CloseableHttpResponse res; while (true) { try (BufferedReader reader = new BufferedReader(new FileReader( QUERY_FILE_DIR + File.separator + random.nextInt(numQueries) + ".json"))) { int length = reader.read(BUFFER); post.setEntity(new StringEntity(new String(BUFFER, 0, length))); } long start = System.currentTimeMillis(); res = client.execute(post); res.close(); counter.getAndIncrement(); totalResponseTime.getAndAdd(System.currentTimeMillis() - start); } } catch (IOException e) { e.printStackTrace(); } } }); } long startTime = System.currentTimeMillis(); while (true) { Thread.sleep(REPORT_INTERVAL_MILLIS); double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND; int count = counter.get(); double avgResponseTime = ((double) totalResponseTime.get()) / count; System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: " + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms"); } }
From source file:com.roncoo.pay.permission.utils.EncryptUtil.java
public static void main(String[] args) { String loginName = "513781560@qq.com"; Long timeStamp = System.currentTimeMillis(); String key = "rcPayLoginSign268"; String sign = RonCooSignUtil.getSign(key, timeStamp, loginName); String url = "http://192.168.1.181:8080/roncoo-dev-admin/mydata/getByLoginName"; Map<String, Object> params = new HashMap<String, Object>(); params.put("userName", loginName); params.put("timeStamp", timeStamp); params.put("sign", sign); String json = JSON.toJSONString(params); String httpResponse = RoncooHttpClientUtils.post(url, json); Map<String, Object> parseObject = JSONObject.parseObject(httpResponse, Map.class); String code = (String) parseObject.get("code"); String desc = (String) parseObject.get("desc"); System.out.println(code);//from ww w .ja va 2 s . co m JSONObject data = (JSONObject) parseObject.get("data"); Map<String, Object> mapInfo = JSONObject.parseObject(data.toJSONString(), Map.class); String returnPWD = (String) mapInfo.get("pwd"); String userId = (String) mapInfo.get("userId"); System.out.println(httpResponse); }