Example usage for com.google.common.base Stopwatch createStarted

List of usage examples for com.google.common.base Stopwatch createStarted

Introduction

In this page you can find the example usage for com.google.common.base Stopwatch createStarted.

Prototype

@CheckReturnValue
public static Stopwatch createStarted() 

Source Link

Document

Creates (and starts) a new stopwatch using System#nanoTime as its time source.

Usage

From source file:suneido.DbTools.java

public static void dumpPrintExit(String dbFilename, String outputFilename) {
    if (Status.OK != checkPrint(dbFilename)) {
        System.out.println("Dump ABORTED - check failed - database CORRUPT");
        System.exit(-1);/* w w w  .j  a  va  2 s  .c o m*/
    }
    try (Database db = Dbpkg.openReadonly(dbFilename)) {
        Stopwatch sw = Stopwatch.createStarted();
        int n = dumpDatabase(db, outputFilename);
        System.out.println(
                "dumped " + n + " tables " + "from " + dbFilename + " to " + outputFilename + " in " + sw);
    }
}

From source file:com.mysema.testutil.Runner.java

public static void run(String label, Benchmark benchmark) throws Exception {
    // warmup/* ww  w . j a  v  a  2 s.  com*/
    benchmark.run(WARMUP);
    System.err.print("- ");

    // run garbage collection
    System.gc();
    System.err.print("- ");

    // perform timing
    Stopwatch stopwatch = Stopwatch.createStarted();
    benchmark.run(BENCHMARK);
    System.err.println(label + " " + stopwatch.stop().toString());
}

From source file:ch.oakmountain.tpa.solver.TPAUtil.java

public static Stopwatch startStopWatch() {
    Stopwatch stopwatch = Stopwatch.createStarted();
    return stopwatch;
}

From source file:com.hortonworks.streamline.common.util.ParallelStreamUtil.java

public static <T> T execute(Supplier<T> supplier, Executor executor) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    LOG.debug("execute start");

    try {//from   w w w.jav  a 2  s  .co m
        CompletableFuture<T> resultFuture = CompletableFuture.supplyAsync(supplier, executor);
        return resultFuture.get();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ExecutionException e) {
        handleExecutionException(e);
        // shouldn't reach here
        throw new IllegalStateException("Shouldn't reach here");
    } finally {
        LOG.debug("execute complete - elapsed: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.stop();
    }
}

From source file:com.persinity.common.db.RelDbUtil.java

/**
 * @param schema//from w  w  w.j a  v a 2 s.  c o  m
 *         to warm up the cache
 */
public static void warmUpCache(final Schema schema, final boolean warmUpFks) {
    log.debug("Warming up {} of type {}", schema, schema.getClass().getSimpleName());
    final Stopwatch st = Stopwatch.createStarted();
    schema.getUserName();
    final Set<String> tableNames = schema.getTableNames();
    log.info("Warming up tables: {} {} {}...", tableNames.size(), warmUpFks ? "with FKs" : "without FKs",
            schema);
    for (String tableName : tableNames) {
        schema.getTableCols(tableName);
        schema.getTablePk(tableName);
        if (warmUpFks) {
            schema.getTableFks(tableName);
        }
    }
    st.stop();
    log.info("Warm up done for {}", st);
}

From source file:org.opendaylight.protocol.bgp.rib.impl.CheckUtil.java

public static void checkReceivedMessages(final SimpleSessionListener listener, final int numberOfMessages)
        throws ReadFailedException {
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
        if (listener.getListMsg().size() != numberOfMessages) {
            Uninterruptibles.sleepUninterruptibly(SLEEP_UNINTERRUPTIBLY, TimeUnit.MILLISECONDS);
        } else {/* w w  w. jav a  2  s  .c om*/
            return;
        }
    }
    Assert.fail();
}

From source file:com.android.messaging.util.GifTranscoder.java

public static boolean transcode(Context context, String filePath, String outFilePath) {
    if (!isEnabled()) {
        return false;
    }//w  w w .j a va2 s.  c om
    final long inputSize = new File(filePath).length();
    Stopwatch stopwatch = Stopwatch.createStarted();
    final boolean success = transcodeInternal(filePath, outFilePath);
    stopwatch.stop();
    final long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
    final long outputSize = new File(outFilePath).length();
    final float compression = (inputSize > 0) ? ((float) outputSize / inputSize) : 0;

    if (success) {
        LogUtil.i(TAG,
                String.format("Resized GIF (%s) in %d ms, %s => %s (%.0f%%)", LogUtil.sanitizePII(filePath),
                        elapsedMs, Formatter.formatShortFileSize(context, inputSize),
                        Formatter.formatShortFileSize(context, outputSize), compression * 100.0f));
    }
    return success;
}

From source file:info_teorija_1.Encode.java

public static void encode(int wordLength, File in, File out) throws IOException {
    Stopwatch total = Stopwatch.createStarted();
    Stopwatch time = Stopwatch.createStarted();

    /* create input/output buffered file streams */
    FileInputStream inputStream = new FileInputStream(in);
    BufferedInputStream src = new BufferedInputStream(inputStream);
    input = new BitInput(src);

    OutputStream dst = new FileOutputStream(out);
    BufferedOutputStream outputStream = new BufferedOutputStream(dst);
    output = new BitOutput(outputStream);

    getFrequenciesAndWriteRemainder(in, wordLength);
    System.out.println("getFrequancies " + time.elapsed(TimeUnit.MILLISECONDS));

    time.stop();//  w  ww  .ja va2 s.  c  om
    time = Stopwatch.createStarted();

    // build tree
    HuffmanTree tree = HuffmanCode.buildTree(byteFreqs);
    System.out.println("BuildTree " + time.elapsed(TimeUnit.MILLISECONDS));

    time.stop();
    time = Stopwatch.createStarted();

    // generateCodes and fill huffmanTable
    HuffmanCode.genCodes(tree, new StringBuffer());
    System.out.println("genCodes " + time.elapsed(TimeUnit.MILLISECONDS));

    Encode.wordLength = wordLength;

    time.stop();
    time = Stopwatch.createStarted();

    output.writeUnsignedInt(4, wordLength - 1);
    output.writeUnsignedLong(32, bytesLength);

    encodeTree(tree);
    System.out.println("encodeTree " + time.elapsed(TimeUnit.MILLISECONDS));
    time.stop();
    time = Stopwatch.createStarted();

    encodeFile();

    System.out.println("encodeFile " + time.elapsed(TimeUnit.MILLISECONDS));
    time.stop();

    outputStream.close();
    inputStream.close();
    System.out.println("TOTAL: " + total.elapsed(TimeUnit.MILLISECONDS));
    total.stop();
}

From source file:info_teorija_1.Decode.java

public static void decode(File in, File out) throws IOException {
    Stopwatch total = Stopwatch.createStarted();
    Stopwatch time = Stopwatch.createStarted();

    FileInputStream src = new FileInputStream(in);
    BufferedInputStream inputStream = new BufferedInputStream(src);
    input = new BitInput(inputStream);

    FileOutputStream dst = new FileOutputStream(out);
    BufferedOutputStream outputStream = new BufferedOutputStream(dst);
    output = new BitOutput(outputStream);

    int remainderLength = input.readUnsignedInt(4);
    int remainder = 0;

    if (remainderLength != 0) {
        remainder = input.readUnsignedInt(15);
    } else {/*from w ww.j  a va 2  s  .c  om*/
        input.readUnsignedInt(15);
    }

    wordLength = input.readUnsignedInt(4) + 1;
    length = input.readUnsignedLong(32);

    System.out.println("setup() " + time.elapsed(TimeUnit.MILLISECONDS));
    time.stop();
    time = Stopwatch.createStarted();

    while (true) {
        if (totalHuffmanLeafs != 0 && totalHuffmanLeafs == currentHuffmanLeafs) {
            break;
        }
        decodeTree();
    }
    System.out.println("decodeTree() " + time.elapsed(TimeUnit.MILLISECONDS));

    time.stop();
    time = Stopwatch.createStarted();

    HuffmanCode.genCodes(tree, new StringBuffer());
    System.out.println("genCodes() " + time.elapsed(TimeUnit.MILLISECONDS));

    time.stop();
    time = Stopwatch.createStarted();

    decodeFile();
    System.out.println("decodeFile() " + time.elapsed(TimeUnit.MILLISECONDS));
    if (remainderLength != 0)
        output.writeUnsignedInt(remainderLength, remainder);

    inputStream.close();
    outputStream.close();
    System.out.println("total: " + total.elapsed(TimeUnit.MILLISECONDS));

}

From source file:de.unentscheidbar.csv2.ProfileMe.java

static long operation() throws Exception {

    Stopwatch sw = Stopwatch.createStarted();
    long ops = 0;
    while (sw.elapsed(TimeUnit.SECONDS) < 1) {
        ops++;//w w  w.  ja  v  a2s. c  om
        for (CsvRow row : CsvFormat.defaultFormat().parser().parse(csv)) {
            if (row.asList().size() < 0)
                throw new AssertionError();
        }
        // for ( CSVRecord row : CSVFormat.DEFAULT.parse( new StringReader( csv ) ) ) {
        // if ( row.size() < 0 ) throw new AssertionError();
        // }
    }
    return ops;
}