List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:ffx.numerics.fft.RowMajorComplex3DCuda.java
/** * <p>//from w w w . ja va2 s . com * main</p> * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { int dimNotFinal = 64; int reps = 10; if (args != null) { try { dimNotFinal = Integer.parseInt(args[0]); if (dimNotFinal < 1) { dimNotFinal = 64; } reps = Integer.parseInt(args[2]); if (reps < 1) { reps = 5; } } catch (Exception e) { } } final int dim = dimNotFinal; System.out.println(String.format( " Initializing a %d cubed grid.\n" + " The best timing out of %d repititions will be used.", dim, reps)); final int dimCubed = dim * dim * dim; /** * Create an array to save the initial input and result. */ double orig[] = new double[dimCubed]; double answer[] = new double[dimCubed]; double data[] = new double[dimCubed * 2]; double recip[] = new double[dimCubed]; Random random = new Random(1); for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { int index = RowMajorComplex3D.iComplex3D(x, y, z, dim, dim); orig[index / 2] = random.nextDouble(); recip[index / 2] = orig[index / 2]; } } } RowMajorComplex3D complex3D = new RowMajorComplex3D(dim, dim, dim); RowMajorComplex3DParallel complex3DParallel = new RowMajorComplex3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed()); RowMajorComplex3DCuda complex3DCUDA = new RowMajorComplex3DCuda(dim, dim, dim, data, recip); Thread cudaThread = new Thread(complex3DCUDA); cudaThread.setPriority(Thread.MAX_PRIORITY); cudaThread.start(); double toSeconds = 0.000000001; long parTime = Long.MAX_VALUE; long seqTime = Long.MAX_VALUE; long clTime = Long.MAX_VALUE; complex3D.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3D.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Sequential: %8.3f", i + 1, toSeconds * time)); if (time < seqTime) { seqTime = time; } } for (int j = 0; j < dimCubed; j++) { answer[j] = data[j * 2]; } complex3DParallel.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DParallel.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Parallel: %8.3f", i + 1, toSeconds * time)); if (time < parTime) { parTime = time; } } double maxError = Double.MIN_VALUE; double rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs(answer[i] - data[2 * i]); if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError)); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DCUDA.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d CUDA: %8.3f", i + 1, toSeconds * time)); if (time < clTime) { clTime = time; } } maxError = Double.MIN_VALUE; double avg = 0.0; rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs((answer[i] - data[2 * i]) / dimCubed); avg += error; if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; avg /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg)); complex3DCUDA.free(); complex3DCUDA = null; System.out.println(String.format(" Best Sequential Time: %8.3f", toSeconds * seqTime)); System.out.println(String.format(" Best Parallel Time: %8.3f", toSeconds * parTime)); System.out.println(String.format(" Best CUDA Time: %8.3f", toSeconds * clTime)); System.out.println(String.format(" Parallel Speedup: %15.5f", (double) seqTime / parTime)); System.out.println(String.format(" CUDA Speedup: %15.5f", (double) seqTime / clTime)); }
From source file:com.l2jfree.util.concurrent.ExecuteWrapper.java
public static void execute(Runnable runnable, long maximumRuntimeInMillisecWithoutWarning) { long begin = System.nanoTime(); try {/*from www . j a va 2s .c o m*/ runnable.run(); } catch (RuntimeException e) { _log.warn("Exception in a Runnable execution:", e); } finally { long runtimeInNanosec = System.nanoTime() - begin; Class<? extends Runnable> clazz = runnable.getClass(); RunnableStatsManager.handleStats(clazz, runtimeInNanosec); long runtimeInMillisec = TimeUnit.NANOSECONDS.toMillis(runtimeInNanosec); if (runtimeInMillisec > maximumRuntimeInMillisecWithoutWarning) { L2TextBuilder tb = L2TextBuilder.newInstance(); tb.append(clazz); tb.append(" - execution time: "); tb.append(runtimeInMillisec); tb.append("msec"); _log.warn(tb.moveToString()); } } }
From source file:com.spotify.annoy.jni.base.Benchmark.java
private static void runBenchmark(String annPath, Integer dim, String queryFile, Integer nnsCount) throws IOException, InterruptedException { AnnoyIndex index = Annoy.loadIndex(annPath, dim); List<Integer> queries = AnnoyTest.parseFileLinesAsInts(queryFile); List<Long> queryTime = new ArrayList<>(queries.size()); for (Integer query : queries) { long t = System.nanoTime(); index.getNearestByItem(query, nnsCount); queryTime.add(System.nanoTime() - t); }/*from www.j a v a2s .co m*/ dispStats(queryTime); }
From source file:com.mgmtp.jfunk.common.random.MathRandom.java
public static long nextSeed() { return SEED_UNIQUIFIER.addAndGet(System.nanoTime()); }
From source file:com.sirti.microservice.hbase.service.HKpiService.java
public HKpiResultSet findAll() { HKpiResultSet hkpiresultset = new HKpiResultSet(); try {//ww w . j a v a 2 s . c o m long starttime = System.nanoTime(); List<HKpi> hkpilist = hKpiDao.findAll(); long endtime = System.nanoTime(); hkpiresultset.setHKpiList(hkpilist); hkpiresultset.setDuration((endtime - starttime) / 1000000); hkpiresultset.setError(Boolean.FALSE); } catch (Exception e) { hkpiresultset.setError(Boolean.TRUE); hkpiresultset.setErrorMsg(e.getLocalizedMessage()); } return hkpiresultset; }
From source file:enumj.NanoTimer.java
public static <R> long nanos(Supplier<R> action, Supplier<String> msg) { print(msg.get());/*from w w w .j a v a2 s .c om*/ final long t0 = System.nanoTime(); final R result = action.get(); return System.nanoTime() - t0; }
From source file:com.proofpoint.units.Duration.java
public static Duration nanosSince(long start) { long end = System.nanoTime(); long value = end - start; double millis = value * millisPerTimeUnit(NANOSECONDS); return new Duration(millis, MILLISECONDS).convertToMostSuccinctTimeUnit(); }
From source file:de.sanandrew.mods.turretmod.registry.assembly.TurretAssemblyRecipes.java
public static void initialize(final ITurretAssemblyRegistry registry) { TmrConstants.LOG.log(Level.INFO, "Initializing Turret Assembly recipes..."); long prevTime = System.nanoTime(); Loader.instance().getActiveModList().forEach(mod -> loadJsonRecipes(mod, registry)); long timeDelta = (System.nanoTime() - prevTime) / 1_000_000; TmrConstants.LOG.log(Level.INFO, String.format("Initializing Turret Assembly recipes done in %d ms. Found %d recipes.", timeDelta, registry.getRecipeList().size())); }
From source file:Main.java
public Main() { this.setLayout(new GridLayout(0, 1)); this.add(label); this.add(new JButton(new AbstractAction("OK") { @Override/*from ww w .java 2s .com*/ public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); b.setText("123"); } })); new Timer(100, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { label.setText(String.valueOf(System.nanoTime())); } }).start(); }
From source file:com.espertech.esper.util.MetricUtil.java
/** * Returns wall time using System#nanoTime. * @return wall time */ public static long getWall() { return System.nanoTime(); }