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:de.sanandrew.mods.turretmod.registry.electrolytegen.ElectrolyteRegistry.java

public static void initialize() {
    TmrConstants.LOG.log(Level.INFO, "Initializing Electrolyte Generator recipes...");
    long prevTime = System.nanoTime();
    Loader.instance().getActiveModList().forEach(ElectrolyteRegistry::loadJsonRecipes);
    long timeDelta = (System.nanoTime() - prevTime) / 1_000_000;
    TmrConstants.LOG.log(Level.INFO,
            String.format("Initializing Electrolyte Generator recipes done in %d ms. Found %d recipes.",
                    timeDelta, ElectrolyteRegistry.getFuelMap().size()));
}

From source file:Main.java

/**
 * Drains the queue as {@link BlockingQueue#drainTo(Collection, int)}, but if the requested
 * {@code numElements} elements are not available, it will wait for them up to the specified
 * timeout.//from   w  w w  .  java2s.  c  o m
 *
 * Taken from Google Guava 18.0 Queues
 *
 * @param q the blocking queue to be drained
 * @param buffer where to add the transferred elements
 * @param numElements the number of elements to be waited for
 * @param timeout how long to wait before giving up, in units of {@code unit}
 * @param unit a {@code TimeUnit} determining how to interpret the timeout parameter
 * @param <E> the type of the queue
 * @return the number of elements transferred
 * @throws InterruptedException if interrupted while waiting
 */
public static <E> int drain(BlockingQueue<E> q, Collection<? super E> buffer, int numElements, long timeout,
        TimeUnit unit) throws InterruptedException {
    buffer = Objects.requireNonNull(buffer);
    /*
     * This code performs one System.nanoTime() more than necessary, and in return, the time to
     * execute Queue#drainTo is not added *on top* of waiting for the timeout (which could make
     * the timeout arbitrarily inaccurate, given a queue that is slow to drain).
     */
    long deadline = System.nanoTime() + unit.toNanos(timeout);
    int added = 0;
    while (added < numElements) {
        // we could rely solely on #poll, but #drainTo might be more efficient when there are multiple
        // elements already available (e.g. LinkedBlockingQueue#drainTo locks only once)
        added += q.drainTo(buffer, numElements - added);
        if (added < numElements) { // not enough elements immediately available; will have to poll
            E e = q.poll(deadline - System.nanoTime(), TimeUnit.NANOSECONDS);
            if (e == null) {
                break; // we already waited enough, and there are no more elements in sight
            }
            buffer.add(e);
            added++;
        }
    }
    return added;
}

From source file:com.linkedin.pinot.controller.utils.SegmentMetadataMockUtils.java

public static SegmentMetadata mockSegmentMetadata(String tableName) {
    String uniqueNumericString = Long.toString(System.nanoTime());
    return mockSegmentMetadata(tableName, tableName + uniqueNumericString, 0, uniqueNumericString);
}

From source file:com.relicum.ipsum.Utils.Profiler.java

public static long endProfiling(String id) {
    final long delta = System.nanoTime();
    Validate.notNull(id, "ID should not be null");
    synchronized (startTimes) {
        return delta - startTimes.remove(id);
    }// w w  w.  j  a v a  2  s . c o m
}

From source file:com.springsource.open.jms.async.AsynchronousMessageTriggerSunnyDayPerformanceTests.java

@Test
public void testCleanData() {
    long start = System.nanoTime();
    for (int i = 0; i < 10000; i++) {
        jmsTemplate.convertAndSend("async", "foo" + i);
    }//from w w  w.  j  a v a  2 s. c  o  m
    long end = System.nanoTime();
    System.out.println("**************************** time past in seconds:" + (end - start));
}

From source file:edu.tum.cs.ias.knowrob.utils.ResourceRetriever.java

/**
 * Creates a temporary directory (normally in the /tmp folder)
 * //from w w w. j a  v  a2 s.co  m
 * @return File with path to created dir
 */
public static String createTempDirectory() {

    String tmpDir = System.getProperty("java.io.tmpdir");

    File temp = new File(tmpDir, "temp" + Long.toString(System.nanoTime()));

    if (!(temp.mkdir())) {
        System.err.println("Could not create temp directory: " + temp.getAbsolutePath());
    }

    return temp.getAbsolutePath();
}

From source file:com.intuit.tank.tools.debugger.PanelBuilder.java

public static File createWorkingDir(AgentDebuggerFrame frame, String baseUrl) {
    try {/* ww w.  j av  a2  s.  co m*/
        File temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
        temp.delete();
        temp = new File(temp.getAbsolutePath() + ".d");
        temp.mkdir();
        workingDir = temp;
        // create settings.xml
        writeSettings(workingDir, getHeaders(baseUrl));
        System.setProperty("WATS_PROPERTIES", workingDir.getAbsolutePath());
    } catch (IOException e) {
        LOG.error("Error creating temp working dir: " + e);
        frame.showError("Error creating temp working dir: " + e);
    }
    return workingDir;
}

From source file:net.kamhon.ieagle.aop.PerformanceAroundAdvice.java

public Object invoke(MethodInvocation arg0) throws Throwable {
    long start = System.nanoTime();
    Object obj = arg0.proceed();/*from  w  w  w .j  a  v  a  2 s .c o  m*/
    long end = System.nanoTime();
    long execution = end - start;
    log.info("Performance. Method = " + arg0.getMethod() + "\n  .Taken Time = " + execution + "(ns)  "
            + execution / 100000 + "(ms)");
    return obj;
}

From source file:net.NET_INFO.java

/**
 * ?//from  w  w w . j  ava 2 s .  co  m
 * @return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
 */
public static long getCurrentMilli() {
    return (System.nanoTime() - START_TIME) / 1000000 + RETURN_TIME;
}

From source file:almira.sample.client.ListCatapults.java

static void executeQuery(ObjectQueryService<Catapult, Long> service) {
    long startTime = System.nanoTime();
    List<Catapult> catapults = service.findAll(START_INDEX, FETCH_SIZE);
    long timeDifference = System.nanoTime() - startTime;

    StringBuilder sb = new StringBuilder();
    sb.append("\nRequesting ");
    sb.append(catapults.size());// w  w  w. jav a2 s  .  co  m
    sb.append(" catapults took: ");
    sb.append(timeDifference / NANOS_IN_SEC);
    sb.append(" ms");
    printMessage(sb.toString());

    for (Catapult c : catapults) {
        printMessage(c.toString());
    }
}