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

public static long contains(Set set) {
    long start, stop, result = 0;
    for (int i = 0; i < 100; i++) {
        start = System.nanoTime();
        set.contains(set.size() - i);//from w  w  w  . ja v a 2 s.  c  o  m
        stop = System.nanoTime();
        result += stop - start;
    }
    return result / 100;
}

From source file:io.anserini.index.IndexClueWeb09b.java

public static void main(String[] args) throws IOException, InterruptedException {

    IndexArgs indexArgs = new IndexArgs();

    CmdLineParser parser = new CmdLineParser(indexArgs, ParserProperties.defaults().withUsageWidth(90));

    try {/*from  w  w w.  j a v a 2  s .co m*/
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        System.err.println("Example: IndexClueWeb09b" + parser.printExample(OptionHandlerFilter.REQUIRED));
        return;
    }

    final long start = System.nanoTime();
    IndexClueWeb09b indexer = new IndexClueWeb09b(indexArgs.input, indexArgs.index);

    indexer.setPositions(indexArgs.positions);
    indexer.setOptimize(indexArgs.optimize);
    indexer.setDocLimit(indexArgs.doclimit);

    LOG.info("Index path: " + indexArgs.index);
    LOG.info("Threads: " + indexArgs.threads);
    LOG.info("Positions: " + indexArgs.positions);
    LOG.info("Optimize (merge segments): " + indexArgs.optimize);
    LOG.info("Doc limit: " + (indexArgs.doclimit == -1 ? "all docs" : "" + indexArgs.doclimit));

    LOG.info("Indexer: start");

    int numIndexed = indexer.indexWithThreads(indexArgs.threads);
    final long durationMillis = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
    LOG.info("Total " + numIndexed + " documents indexed in "
            + DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss"));
}

From source file:Main.java

public static long add(List list) {
    long start, stop, result = 0;
    for (int i = 0; i < 100; i++) {
        start = System.nanoTime();
        list.add(list.size() + 1 + i);//ww  w  .j a v  a2 s.com
        stop = System.nanoTime();
        result += stop - start;
    }
    return result / 100;
}

From source file:Main.java

public static long remove(List list) {
    long start, stop, result = 0;
    for (int i = 0; i < 100; i++) {
        start = System.nanoTime();
        list.remove(list.size() - 1 - i);
        stop = System.nanoTime();
        result += stop - start;//from w w w.ja  v a  2s.  c  o m
    }
    return result / 100;
}

From source file:Main.java

public static long populate(Set set, int size) {
    long start, stop, result = 0;
    for (int i = 0; i < 100; i++) {
        set.clear();// w  w w .j av a 2 s.  c o m
        start = System.nanoTime();
        for (int j = 0; j < size; j++) {
            set.add(j);
        }
        stop = System.nanoTime();
        result += stop - start;
    }
    return result / 100;
}

From source file:com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter.java

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Usage: $0 <table directory with segments>");
        System.exit(1);/* w  w w .j ava  2  s  .c o m*/
    }
    File tableDirectory = new File(args[0]);
    Preconditions.checkState(tableDirectory.exists(), "Directory: {} does not exist", tableDirectory);
    Preconditions.checkState(tableDirectory.isDirectory(), "Path: {} is not a directory", tableDirectory);
    File[] files = tableDirectory.listFiles();
    SegmentFormatConverter converter = new SegmentV1V2ToV3FormatConverter();

    for (File file : files) {
        if (!file.isDirectory()) {
            System.out.println("Path: " + file + " is not a directory. Skipping...");
            continue;
        }
        long startTimeNano = System.nanoTime();
        converter.convert(file);
        long endTimeNano = System.nanoTime();
        long latency = (endTimeNano - startTimeNano) / (1000 * 1000);
        System.out.println("Converting segment: " + file + " took " + latency + " milliseconds");
    }
}

From source file:Main.java

/**
 * Retrieve a timestamp for the current instant, in nanoseconds.
 *
 * @return Current instant./*from  ww  w. j av a2  s. c  om*/
 */
public static long nowNanos() {
    return System.nanoTime();
}

From source file:Main.java

public static void sleep(final long millis) {
    long start;//from  w  ww  .  j a v a  2s. c  o m
    long end;
    long remaining = millis;
    do {
        start = System.nanoTime();
        try {
            Thread.sleep(remaining);
            remaining = 0;
        } catch (final InterruptedException ex) {
            end = System.nanoTime();
            remaining -= (end - start) / 1000000;
        }
    } while (remaining > 0);
}

From source file:Main.java

private static long getCurrentTime(TimeUnit timeUnit) {

    switch (timeUnit) {
    case NANOSECONDS:
        return System.nanoTime();

    case MILLISECONDS:
        return System.currentTimeMillis();

    default:/*from www  .j  a  v a  2  s .  c om*/
        return System.currentTimeMillis();
    }

}

From source file:Main.java

public static long add(Set set) {
    long start, stop, result = 0;
    for (int i = 0; i < 100; i++) {
        start = System.nanoTime();
        set.add(set.size() + 1 + i);//  w w w . j  a  v  a2 s  .c o m
        stop = System.nanoTime();
        result += stop - start;
    }
    return result / 100;
}