List of usage examples for java.util.concurrent TimeUnit MICROSECONDS
TimeUnit MICROSECONDS
To view the source code for java.util.concurrent TimeUnit MICROSECONDS.
Click Source Link
From source file:CreateTest.java
public static void main(String[] args) { target = 10000;/*from w w w. j a v a 2 s . c o m*/ doTestCreate(); doTestPool(8); doTestLoop(); target = Integer.parseInt(args[0]); cleanGC(); Timestamp createTS = new Timestamp(TimeUnit.MICROSECONDS); doTestCreate(); createTS.stop(); System.out.println("Create thread test took " + createTS); cleanGC(); Timestamp pool8TS = new Timestamp(TimeUnit.MICROSECONDS); doTestPool(8); pool8TS.stop(); System.out.println("Pool test (8 threads) took " + pool8TS); cleanGC(); Timestamp poolTS = new Timestamp(TimeUnit.MICROSECONDS); doTestPool(1); poolTS.stop(); System.out.println("Pool test (1 thread) took " + poolTS); cleanGC(); Timestamp loopTS = new Timestamp(TimeUnit.MICROSECONDS); doTestLoop(); loopTS.stop(); System.out.println("Loop test took " + loopTS); double d = ((double) (createTS.elapsedTime() - loopTS.elapsedTime())) / target; System.out.println("Creating a thread took " + d + " " + loopTS.units() + " per thread"); d = ((double) (createTS.elapsedTime() - poolTS.elapsedTime())) / target; System.out.println("Using a thread pool (1 thread) saved " + d + " " + loopTS.units() + " per task"); d = ((double) (createTS.elapsedTime() - pool8TS.elapsedTime())) / target; System.out.println("Using a thread pool (8 threads) saved " + d + " " + loopTS.units() + " per task"); d = ((double) (poolTS.elapsedTime() - loopTS.elapsedTime())) / target; System.out.println("Thread pool overhead (1 thread) is " + d + " " + loopTS.units() + " per task"); d = ((double) (pool8TS.elapsedTime() - loopTS.elapsedTime())) / target; System.out.println("Thread pool overhead (8 threads) is " + d + " " + loopTS.units() + " per task"); }
From source file:example.SendNumbers.java
/** * @param args//from w w w . j a v a 2s . co m * @throws MalformedURLException */ public static void main(String[] args) throws MalformedURLException { AEONSDK sdk = new AEONSDK(Config.PUB_URL); for (int i = 0; i <= 500; i++) { JSONObject data = new JSONObject(); try { data.put("number", i); System.out.println(data.toString()); sdk.publish(data, new MyAEONCallbacks()); TimeUnit.MICROSECONDS.sleep(200); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.couchbase.roadrunner.RoadRunner.java
/** * Initialize the RoadRunner.//w ww . ja v a 2s . c o m * * This method is responsible for parsing the passed in command line arguments * and also dispatch the bootstrapping of the actual workload runner. * * @param args Command line arguments to be passed in. */ public static void main(final String[] args) { CommandLine params = null; try { params = parseCommandLine(args); } catch (ParseException ex) { LOGGER.error("Exception while parsing command line!", ex); System.exit(-1); } if (params.hasOption(OPT_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("roadrunner", getCommandLineOptions()); System.exit(0); } GlobalConfig config = GlobalConfig.fromCommandLine(params); WorkloadDispatcher dispatcher = new WorkloadDispatcher(config); LOGGER.info("Running with Config: " + config.toString()); try { LOGGER.debug("Initializing ClientHandlers."); dispatcher.init(); } catch (Exception ex) { LOGGER.error("Error while initializing the ClientHandlers: ", ex); System.exit(-1); } Stopwatch workloadStopwatch = new Stopwatch().start(); try { LOGGER.info("Running Workload."); dispatcher.dispatchWorkload(); } catch (Exception ex) { LOGGER.error("Error while running the Workload: ", ex); System.exit(-1); } workloadStopwatch.stop(); LOGGER.debug("Finished Workload."); LOGGER.info("==== RESULTS ===="); dispatcher.prepareMeasures(); long totalOps = dispatcher.getTotalOps(); long measuredOps = dispatcher.getMeasuredOps(); LOGGER.info("Operations: measured " + measuredOps + "ops out of total " + totalOps + "ops."); Map<String, List<Stopwatch>> measures = dispatcher.getMeasures(); for (Map.Entry<String, List<Stopwatch>> entry : measures.entrySet()) { Histogram h = new Histogram(60 * 60 * 1000, 5); for (Stopwatch watch : entry.getValue()) { h.recordValue(watch.elapsed(TimeUnit.MICROSECONDS)); } LOGGER.info("Percentile (microseconds) for \"" + entry.getKey() + "\" Workload:"); LOGGER.info(" 50%:" + (Math.round(h.getValueAtPercentile(0.5) * 100) / 100) + " 75%:" + (Math.round(h.getValueAtPercentile(0.75) * 100) / 100) + " 95%:" + (Math.round(h.getValueAtPercentile(0.95) * 100) / 100) + " 99%:" + (Math.round(h.getValueAtPercentile(0.99) * 100) / 100)); } LOGGER.info("Elapsed: " + workloadStopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms"); List<Stopwatch> elapsedThreads = dispatcher.getThreadElapsed(); long shortestThread = 0; long longestThread = 0; for (Stopwatch threadWatch : elapsedThreads) { long threadMs = threadWatch.elapsed(TimeUnit.MILLISECONDS); if (longestThread == 0 || threadMs > longestThread) { longestThread = threadMs; } if (shortestThread == 0 || threadMs < shortestThread) { shortestThread = threadMs; } } LOGGER.info("Shortest Thread: " + shortestThread + "ms"); LOGGER.info("Longest Thread: " + longestThread + "ms"); }
From source file:org.messageforge.fixutil.bin2fix.BinaryToFIX.java
public static void main(String[] args) { final Options options = new Options(); options.addOption("pcap", false, "Indicates this is a pcap file and needs reassembly"); options.addOption("dir", true, "Directory (all files will be parsed"); options.addOption("in", true, "Input file"); options.addOption("out", true, "Output file"); options.addOption("fields", true, "Fields (comma separated). Use \"Bytes\" to display the raw message"); options.addOption("msgTypes", true, "Filter message types (comma separated)"); options.addOption("compIDs", true, "Filter Sender/TargetCompIDs (comma separated)"); options.addOption("appOnly", false, "Filter session messages"); options.addOption("sessionDict", true, "Session dictionary (or both if pre FIX5.0)"); options.addOption("appDict", true, "Application dictionary"); options.addOption("filter", true, "Packet filter"); options.addOption("millis", false, "Convert latency to milliseconds"); final CommandLineParser parser = new PosixParser(); try {/*from w w w. j av a 2s . c o m*/ final CommandLine line = parser.parse(options, args); if (line.hasOption("fields")) { } else if (!line.hasOption("appDict")) { error(options); } final OutputStream ostream = line.hasOption("out") ? new FileOutputStream(new File(line.getOptionValue("out"))) : System.out; final List<String> msgTypes = line.hasOption("msgTypes") ? Arrays.asList(line.getOptionValue("msgTypes").split(",")) : null; final List<String> compIDs = line.hasOption("compIDs") ? Arrays.asList(line.getOptionValue("compIDs").split(",")) : null; final boolean isPcap = line.hasOption("pcap"); final boolean appOnly = line.hasOption("appOnly"); final List<String> fields = new ArrayList<String>( Arrays.asList(line.getOptionValue("fields").split(","))); final DataDictionary appDict = new DataDictionary(new FileInputStream(line.getOptionValue("appDict"))); final DataDictionary sessionDict = new DataDictionary( new FileInputStream(line.getOptionValue("sessionDict"))); final String filter = line.hasOption("filter") ? line.getOptionValue("filter") : null; final TimeUnit latencyTU = line.hasOption("millis") ? TimeUnit.MILLISECONDS : TimeUnit.MICROSECONDS; if (isPcap) { fields.add(0, "Capture Timestamp"); fields.add(1, "Capture Micros"); fields.add(2, "Latency"); } final CSVWriter writer = new CSVWriter(new OutputStreamWriter(ostream)); writer.writeNext(fields.toArray(new String[fields.size()])); if (line.hasOption("dir")) { final File dir = new File(line.getOptionValue("dir")); for (File file : dir.listFiles()) { if (file.isFile()) { log.info("processing file " + file.getName()); new BinaryToFIX(file, isPcap, writer, fields, msgTypes, compIDs, appOnly, sessionDict, appDict, filter, latencyTU).run(); } } } else if (line.hasOption("in")) { new BinaryToFIX(new File(line.getOptionValue("in")), isPcap, writer, fields, msgTypes, compIDs, appOnly, sessionDict, appDict, filter, latencyTU).run(); } else { error(options); } writer.flush(); writer.close(); } catch (Exception ex) { log.error(ex.getMessage(), ex); } }
From source file:Main.java
public static String printTime(long time, TimeUnit unit) { long ns = TimeUnit.NANOSECONDS.convert(time, unit); long us = TimeUnit.MICROSECONDS.convert(time, unit); long ms = TimeUnit.MILLISECONDS.convert(time, unit); long secs = TimeUnit.SECONDS.convert(time, unit); if (secs > 0) return secs + "s"; if (ms > 0) return ms + "ms"; if (us > 0) return us + " us"; return ns + "ns"; }
From source file:Main.java
public static TimeUnit convert(ChronoUnit tu) { if (tu == null) { return null; }//from w w w .j a va 2s .c o m switch (tu) { case DAYS: return TimeUnit.DAYS; case HOURS: return TimeUnit.HOURS; case MINUTES: return TimeUnit.MINUTES; case SECONDS: return TimeUnit.SECONDS; case MICROS: return TimeUnit.MICROSECONDS; case MILLIS: return TimeUnit.MILLISECONDS; case NANOS: return TimeUnit.NANOSECONDS; default: //TODO support the rest throw new UnsupportedOperationException("Man, use a real temporal unit"); } }
From source file:edu.umich.robot.util.Poses.java
public static pose_t elaborate(pose_t oldPose, pose_t newPose) { if (oldPose.utime == 0) return newPose; // elaborate to get velocities from odometry // (new usec - old usec) * 1 / usec in sec double dt = (newPose.utime - oldPose.utime) / (double) TimeUnit.MICROSECONDS.convert(1, TimeUnit.SECONDS); if (dt < MIN_ELABORATION_INTERVAL_SEC) return oldPose; // TODO: may need modification for smoothing newPose.vel[0] = (newPose.pos[0] - oldPose.pos[0]) * (1.0 / dt); newPose.vel[1] = (newPose.pos[1] - oldPose.pos[1]) * (1.0 / dt); double newTheta = LinAlg.quatToRollPitchYaw(newPose.orientation)[2]; newTheta = MathUtil.mod2pi(newTheta); double oldTheta = LinAlg.quatToRollPitchYaw(oldPose.orientation)[2]; oldTheta = MathUtil.mod2pi(oldTheta); newPose.rotation_rate[2] = MathUtil.mod2pi(newTheta - oldTheta) * (1.0 / dt); if (logger.isTraceEnabled()) { double xvel = LinAlg.rotate2(newPose.vel, -newTheta)[0]; logger.trace(String.format("dt%1.5f vx%1.3f vy%1.3f r%1.3f xv%1.3f", dt, newPose.vel[0], newPose.vel[1], newPose.rotation_rate[2], xvel)); }//from ww w .j a va 2 s. c o m return newPose; }
From source file:test.RunTest.java
public static Object readObject(String fileName) { long begin = System.nanoTime(); BufferedInputStream fis = null; try {//ww w . ja va2s. co m Object object; fis = new BufferedInputStream(new FileInputStream(fileName)); Hessian2Input ois = new Hessian2Input(fis); ois.setCloseStreamOnClose(true); object = ois.readObject(); ois.close(); long end = System.nanoTime(); logger.info("Time for deserize java object file " + fileName + " duration micro seconds=" + TimeUnit.MICROSECONDS.convert((end - begin), TimeUnit.NANOSECONDS)); return object; } catch (Exception ex) { if (fis != null) { try { fis.close(); } catch (IOException e) { logger.error(e.getMessage(), e); } } throw new RuntimeException(ex.getMessage(), ex); } }
From source file:org.asoem.greyfish.utils.collect.UnrolledListAT.java
protected static <T> long measureFindFirstIterative(final List<T> list, final Iterable<? extends Predicate<? super T>> predicates) { final Stopwatch stopwatch = Stopwatch.createStarted(); for (Predicate<? super T> predicate : predicates) { findFirstIterative(list, predicate); }// w w w . ja v a 2s. c o m return stopwatch.elapsed(TimeUnit.MICROSECONDS); }
From source file:com.clustercontrol.monitor.run.util.ParallelExecution.java
/** * /*from w w w . j a va2 s .com*/ */ private ParallelExecution() { log.debug("init()"); int m_maxThreadPool = HinemosPropertyUtil .getHinemosPropertyNum("monitor.common.thread.pool", Long.valueOf(10)).intValue(); log.info("monitor.common.thread.pool: " + m_maxThreadPool); es = new MonitoredThreadPoolExecutor(m_maxThreadPool, m_maxThreadPool, 0L, TimeUnit.MICROSECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { return new Thread(r, "MonitorWorker-" + _count++); } }, new ThreadPoolExecutor.AbortPolicy()); log.debug("ParallelExecution() ExecutorService is " + es.getClass().getCanonicalName()); log.debug("ParallelExecution() securityManager is " + System.getSecurityManager()); }