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:UUIDGenerator.java

/**
 * MD5 a random string with localhost/date etc will return 128 bits construct a string of 18
 * characters from those bits.//from  www.j av a 2 s .co  m
 *
 * @return string
 */
public static String getUUID() {
    if (baseUUID == null) {
        baseUUID = getInitialUUID();
        baseUUID = "urn:uuid:" + baseUUID;
    }
    if (++incrementingValue >= Long.MAX_VALUE) {
        incrementingValue = 0;
    }

    if (useNano) {
        return baseUUID + (System.nanoTime() + incrementingValue) + Integer.toString(myRand.nextInt());
    } else {

        return baseUUID + (System.currentTimeMillis() + incrementingValue + Integer.toString(myRand.nextInt()));
    }

}

From source file:AtomicSimpleRandom.java

public AtomicSimpleRandom() {
    this.seed = System.nanoTime() + seq.getAndAdd(129);
}

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

public UnicoStoricoResultSet findAll() {
    UnicoStoricoResultSet hkpiresultset = new UnicoStoricoResultSet();

    try {//ww w. j  a  v a2  s  . com
        long starttime = System.nanoTime();
        List<UnicoStorico> hkpilist = unicoStoricoDao.findAll();
        long endtime = System.nanoTime();
        hkpiresultset.setList(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.ms.commons.lang.RangeBuilderTest.java

@Test
public void testPrimitive() {
    List<Person> data = new ArrayList<Person>();
    for (int i = 0; i < 5; i++) {
        Random r = new Random(System.nanoTime());
        Person p = new Person();
        p.setSalary(r.nextFloat());//  w  ww. j  ava 2 s.  c o  m
        p.setAge((r.nextInt(10)));
        p.setId(r.nextLong());
        p.setSex(r.nextInt(10));
        p.setName("name" + r.nextInt(10));
        data.add(p);
    }
    println(data);
    Range range = RangeBuilder.data(data).property("age").range();
    println(range);
    range = RangeBuilder.data(data).property("name").keyName("newName").range();
    println(range);
    range = RangeBuilder.data(data).property("salary").desc().range();
    println(range);
    range = RangeBuilder.data(data).property("id").asc().range();
    println(range);
}

From source file:com.musevisions.android.SudokuSolver.SudokuRetriever.java

/**
 * Loads pictures data. This method may take long, so be sure to call it asynchronously without
 * blocking the main thread./*from w  w  w  .jav  a  2s  . c om*/
 */
public synchronized void prepare() {
    // Clear in case images need to be updated
    long startTime = System.nanoTime();

    mContents = loadFromURL();

    long deltaTime = System.nanoTime() - startTime;
    double timeMs = (double) deltaTime / 1E6;

    Log.i(TAG, "Done querying URL in, " + timeMs + " ms. " + mContents.length() + " elements found.");
}

From source file:com.webbfontaine.valuewebb.irms.core.DefaultRuleScriptSourceGenerator.java

@Override
public String generateScriptName(String baseName, String scriptText) {
    return String.format("%s%s%d", baseName, RandomStringUtils.randomAlphabetic(8), System.nanoTime());
}

From source file:AtomicPseudoRandom.java

public AtomicPseudoRandom() {
    this((int) System.nanoTime());
}

From source file:info.novatec.flyway.branching.extension.BranchingMigrationH2IntegrationTest.java

@Override
protected String getJdbcUrl() {
    databasePath = "dbmigration" + System.nanoTime();
    return "jdbc:h2:file:./target/" + databasePath;
}

From source file:enumj.NanoTimer.java

public static <U, R> long buildNanos(Supplier<U> construction, Function<U, R> action, Supplier<String> msg) {
    print("Construction: " + msg.get());
    final U input = construction.get();
    print("Action: " + msg.get());
    final long t0 = System.nanoTime();
    final R result = action.apply(input);
    return System.nanoTime() - t0;
}

From source file:by.zuyeu.deyestracker.core.detection.task.DetectEyesTask.java

@Override
public Rect[] call() throws Exception {
    long startTime = System.nanoTime();
    Rect[] result = new Rect[0];
    if (frame != null && !frame.empty()) {
        for (EyesDetector detector : detectors) {
            Rect[] detectedEyes = detector.detectEyes(frame);
            result = ArrayUtils.addAll(result, detectedEyes);
        }/*from  w w w. ja v  a2 s  . c o m*/
    }
    long endTime = System.nanoTime();
    LOG.debug("eyes detected = {}", result.length);
    LOG.debug("detection time: {} ms", (float) (endTime - startTime) / 1000000);
    return result;
}