Example usage for java.lang System nanoTime

List of usage examples for java.lang System nanoTime

Introduction

In this page you can find the example usage for java.lang System nanoTime.

Prototype

@HotSpotIntrinsicCandidate
public static native long nanoTime();

Source Link

Document

Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.

Usage

From source file:org.mjunx.LoggerLoadTester.java

@Override
public void run(String... args) throws Exception {
    final Logger logger = LogManager.getLogger();
    final long start = System.nanoTime();
    for (int i = 0; i < ITERATIONS; i++) {
        logger.info("Test log message #{}", i);
    }/* ww  w .  j  a v a  2 s  .  co m*/
    final long duration = System.nanoTime() - start;
    final BigDecimal average = BigDecimal.valueOf(duration).divide(BigDecimal.valueOf(ITERATIONS));
    System.out.append("Average time per operation: ").append(average.toPlainString()).append(" ns.\n");
}

From source file:io.kahu.hawaii.util.call.statistics.RequestStatistic.java

public void endRequest() {
    this.endNano = System.nanoTime();
}

From source file:dk.ekot.misc.SynchronizedCache.java

public void add(Path fullSourcePath, Path fullCachePath) throws IOException {
    long start = System.nanoTime();
    synchronized (fileCopyLockSet) {
        while (fileCopyLockSet.contains(fullCachePath.toString())) {
            log.trace("Waiting for " + fullCachePath + " to be removed from lock set");
            try {
                fileCopyLockSet.wait(1000);
            } catch (InterruptedException e) {
                log.debug("Interrupted or timed out while waiting for changes in fileCopyLockSet, looking for "
                        + fullCachePath);
            }//w ww  . j a  v a 2  s .c  o m
            log.trace("Interrupted waiting for " + fullCachePath + " after "
                    + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) + "ms");
        }
        log.trace("Adding to lock set: " + fullCachePath);
        fileCopyLockSet.add(fullCachePath.toString());
    }

    try {
        long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
        if (elapsed > 250) {
            log.warn(String.format("File copy of '%s' delayed %d ms.  Possible DDOS.", fullCachePath.toString(),
                    elapsed));
        }
        copy(fullSourcePath, fullCachePath);
    } finally {
        log.trace("Removing " + fullCachePath + " from lock set");
        // https://docs.oracle.com/javase/tutorial/essential/concurrency/guardmeth.html
        synchronized (fileCopyLockSet) {
            fileCopyLockSet.remove(fullCachePath.toString());
            fileCopyLockSet.notifyAll(); // Notify waiters
        }
    }
    Path extractedPath = fullSourcePath;
    cache.put(extractedPath.toString(), fullCachePath);
}

From source file:net.rwx.maven.asciidoc.utils.FileUtils.java

public static String getTemporaryDirectory() throws IOException {
    StringBuilder builder = new StringBuilder();

    builder.append(getTempDirectoryPath());
    builder.append(File.separator);
    builder.append("asciidoc-maven-plugin");
    builder.append(Long.toString(System.nanoTime()));

    File directory = new File(builder.toString());
    forceMkdir(directory);/*from w w w. jav a 2  s.  co m*/
    // forceDeleteOnExit( directory );

    return directory.getAbsolutePath();
}

From source file:com.sirti.microservice.hbase.service.HKpiService.java

public HKpiResultSet findFilterAlarms(String filter) {
    HKpiResultSet hkpiresultset = new HKpiResultSet();

    try {/*w w  w.  j ava  2s .  c  om*/
        long starttime = System.nanoTime();
        List<HKpi> hkpilist = hKpiDao.findFilterHKpi(filter);
        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:com.centeractive.ws.builder.DefinitionSaveTest.java

public static File createTempFolder(String name) throws IOException {
    File tempFolder = File.createTempFile(name, Long.toString(System.nanoTime()));
    if (!tempFolder.delete()) {
        throw new RuntimeException("cannot delete tmp file");
    }// www. j  a va  2 s.com
    if (!tempFolder.mkdir()) {
        throw new RuntimeException("cannot create tmp folder");
    }
    return tempFolder;
}

From source file:net.java.jless.smartcard.ChainingSmartcard.java

public static APDURes transmitChain(Smartcard card, byte[] apdu) throws SmartcardException {
    List<byte[]> pieces = chain(apdu, 255);

    // log full apdu if chaining
    if (pieces.size() > 1 && log.isDebugEnabled()) {
        log.debug("chaining (" + apdu.length + " bytes, " + pieces.size() + " pieces) > " + Hex.b2s(apdu));
    }//ww w  .  j  a v a  2s. c  o m

    APDURes res = null;
    for (byte[] piece : pieces) {
        StringBuilder sb = new StringBuilder("apdu (" + piece.length + ") >\n");
        Hex.dump(sb, piece, 0, piece.length, "  ", 32, false);
        log.debug(sb.toString());
        long start = System.nanoTime();
        res = card.transmit(piece);
        long end = System.nanoTime();
        long timeTaken = (end - start) / 1000000;
        sb = new StringBuilder(timeTaken + " ms - apdu (" + res.getBytes().length + ") <\n");
        Hex.dump(sb, res.getBytes(), 0, res.getBytes().length, "  ", 32, false);
        log.debug(sb.toString());
        // if we don't get 0x9000 or 0x61?? then this is error so quit early
        if (res.getSW() != 0x9000 && res.getSW1() != 0x61) {
            return res;
        }
    }
    return res;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.Timing.java

/**
 * Starts a timer with the specified name.
 * /*  w  w w .  jav  a2  s .c o m*/
 * @param name the name of the timer to start
 */
public static void startTimer(String name) {
    if (openTimers.containsKey(name)) {
        throw new IllegalArgumentException("timer already exists");
    }

    openTimers.put(name, System.nanoTime());
}

From source file:org.jimsey.projects.turbine.furnace.web.PingController.java

@RequestMapping("/ping")
public Long ping() {
    return System.nanoTime();
}

From source file:com.github.jmabuin.blaspark.solvers.ConjugateGradientSolver.java

/**
 * We are going to perform Ax = b where A is the input matrix. x is the output vector and b is the input vector
 * @param matrix The input matrix A/*from w ww  .j  a v  a2s.  c  o  m*/
 * @param inputVector The input vector b
 * @param outputVector The output vector x
 * @param numIterations The max number of iterations to perform
 * @return
 */
public static DenseVector solve(DistributedMatrix matrix, DenseVector inputVector, DenseVector outputVector,
        long numIterations, JavaSparkContext jsc) {

    if (numIterations == 0) {
        numIterations = inputVector.size() * 2;
    }

    boolean stop = false;

    long start = System.nanoTime();

    DenseVector r = inputVector.copy();

    //Fin -- r = b-A*x

    DenseVector Ap = Vectors.zeros((int) matrix.numRows()).toDense();

    //p=r
    DenseVector p = r.copy();

    //rsold = r*r
    //double rsold = L1.multiply(r,r);
    double rsold = BLAS.dot(r, r);

    double alpha = 0.0;

    double rsnew = 0.0;

    int k = 0;

    while (!stop) {

        //Inicio -- Ap=A*p
        //Ap = L2.DGEMV(1.0, matrix, p, 0.0, Ap, jsc);
        Ap = L2.DGEMV(1.0, matrix, p, 0.0, Ap, jsc);

        //Fin -- Ap=A*p

        //alpha=rsold/(p'*Ap)
        //alpha = rsold/L1.multiply(p,Ap);
        alpha = rsold / BLAS.dot(p, Ap);

        //x=x+alpha*p

        BLAS.axpy(alpha, p, outputVector);

        //r=r-alpha*Ap
        BLAS.axpy(-alpha, Ap, r);

        //rsnew = r'*r
        rsnew = BLAS.dot(r, r);

        if ((Math.sqrt(rsnew) <= EPSILON) || (k >= (numIterations))) {
            stop = true;
        }

        //p=r+rsnew/rsold*p
        BLAS.scal((rsnew / rsold), p);
        BLAS.axpy(1.0, r, p);

        /*
        LOG.info("JMAbuin ["+k+"]Current rsold is: "+rsold);
        LOG.info("JMAbuin ["+k+"]Current alpha is: "+alpha);
        LOG.info("JMAbuin ["+k+"]First Ap is: "+Ap.apply(0));
        LOG.info("JMAbuin ["+k+"]Cumsum Ap is: "+cumsum(Ap));
        LOG.info("JMAbuin ["+k+"]First P is: "+p.apply(0));
        LOG.info("JMAbuin ["+k+"]Cumsum P is: "+cumsum(p));
        LOG.info("JMAbuin ["+k+"]First X is: "+X.apply(0));
        LOG.info("JMAbuin ["+k+"]Cumsum X is: "+cumsum(X));
        LOG.info("JMAbuin ["+k+"]First R is: "+r.apply(0));
        LOG.info("JMAbuin ["+k+"]Cumsum R is: "+cumsum(r));
        LOG.info("JMAbuin ["+k+"]Current rsnew is: "+rsnew);
        */

        rsold = rsnew;

        //LOG.info("JMAbuin ["+k+"]New rsold is: "+rsold);

        //runtime.gc();
        //long memory = runtime.totalMemory() - runtime.freeMemory();
        //System.out.println("Used memory iterarion "+k+" is megabytes: " + memory/(1024L * 1024L));
        k++;

    }

    //FIN GRADIENTE CONJUGADO

    long end = System.nanoTime();

    LOG.warn("Total time in solve system is: " + (end - start) / 1e9 + " and " + k + " iterations.");

    return outputVector;

}