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

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

Introduction

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

Prototype

public Stopwatch stop() 

Source Link

Document

Stops the stopwatch.

Usage

From source file:GuavaStopwatch.java

private static void demonstrateStopwatch() {
    Stopwatch stopWatch = new Stopwatch();
    System.out.println("Is stopwatch running? " + stopWatch.isRunning());

    stopWatch.start();/*from  w ww  . j  a  v  a2 s.co m*/

    for (int i = 0; i < 1000; i++) {
        System.out.println("Is stopwatch running? " + stopWatch.isRunning());
    }

    stopWatch.stop();
    System.out.println("Our loop took : " + stopWatch.elapsedTime(TimeUnit.MILLISECONDS) + " milliseconds");
}

From source file:processing.BaselineCalculator.java

private static List<int[]> getPopularTags(BookmarkReader reader, int sampleSize, int limit) {
    timeString = "";
    List<int[]> tags = new ArrayList<int[]>();
    Stopwatch timer = new Stopwatch();
    timer.start();/* w  w w .  j a  va2 s.c  om*/

    int[] tagIDs = getPopularTagList(reader, limit);

    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timer = new Stopwatch();
    timer.start();
    for (int j = 0; j < sampleSize; j++) {
        tags.add(tagIDs);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timeString += ("Full training time: " + trainingTime + "\n");
    timeString += ("Full test time: " + testTime + "\n");
    timeString += ("Average test time: " + testTime / sampleSize) + "\n";
    timeString += ("Total time: " + (trainingTime + testTime) + "\n");
    return tags;
}

From source file:edu.illinois.keshmesh.detector.Main.java

private static BasicAnalysisData initBytecodeAnalysis(IJavaProject javaProject, Reporter reporter,
        ConfigurationOptions configurationOptions) throws WALAInitializationException {
    KeshmeshCGModel model;//from ww w .  j a  v  a  2 s . c  o m
    try {
        String exclusionsFileName = FileProvider
                .getFileFromPlugin(Activator.getDefault(), "EclipseDefaultExclusions.txt").getAbsolutePath();
        model = new KeshmeshCGModel(javaProject, exclusionsFileName,
                configurationOptions.getObjectSensitivityLevel());
        Stopwatch stopWatch = Stopwatch.createStarted();
        model.buildGraph();
        stopWatch.stop();
        reporter.report(new KeyValuePair("CALL_GRAPH_CONSTRUCTION_TIME_IN_MILLISECONDS",
                String.valueOf(stopWatch.elapsed(TimeUnit.MILLISECONDS))));
        reportEntryPointStatistics(reporter, model.getEntryPoints());
        dumpEntryPoints(model.getEntryPoints());
    } catch (Exception e) {
        throw new Exceptions.WALAInitializationException(e);
    }
    CallGraph callGraph = model.getGraph();
    reportCallGraphStatistics(reporter, callGraph);
    PointerAnalysis pointerAnalysis = model.getPointerAnalysis();
    HeapModel heapModel = pointerAnalysis.getHeapModel();
    BasicHeapGraph heapGraph = new BasicHeapGraph(pointerAnalysis, callGraph);
    if (configurationOptions.shouldDumpHeapGraph()) {
        dumpHeapGraph(heapGraph);
    }
    reporter.report(
            new KeyValuePair("NUMBER_OF_NODES_OF_HEAP_GRAPH", String.valueOf(heapGraph.getNumberOfNodes())));
    if (!hasShownGraphs) {
        try {
            DisplayUtils.displayGraph(callGraph);
            DisplayUtils.displayGraph(heapGraph);
            hasShownGraphs = true;
        } catch (WalaException e) {
            throw new WALAInitializationException(e);
        }
    }
    IClassHierarchy classHierarchy = model.getClassHierarchy();
    reporter.report(new KeyValuePair("NUMBER_OF_CLASSES", String.valueOf(classHierarchy.getNumberOfClasses())));
    return new BasicAnalysisData(classHierarchy, callGraph, pointerAnalysis, heapModel, heapGraph);
}

From source file:hr.fer.tel.rovkp.lab01.Program.java

public static void zad2(String from, String to) {
    Stopwatch timer = new Stopwatch().start();

    FileReaderWriter frw = new FileReaderWriter();
    try {//from  w  w w .j  a  v  a2 s  .c  o m
        frw.work(from, to, StandardCharsets.ISO_8859_1);
    } catch (URISyntaxException | IOException ex) {
        System.err.println(ex);
    } catch (Exception ex) {
        System.err.println(ex);
    }

    timer.stop();
    System.out.println("Read " + frw.readLinesCount() + " lines from " + frw.readFilesCount() + " files.");
    System.out.println("Program finished in " + timer.elapsedTime(TimeUnit.SECONDS) + " seconds.");
}

From source file:processing.MPurCalculator.java

public static List<Map<Integer, Double>> startLanguageModelCreation(BookmarkReader reader, int sampleSize,
        boolean sorting, boolean userBased, boolean resBased, int beta) {
    int size = reader.getBookmarks().size();
    int trainSize = size - sampleSize;

    Stopwatch timer = new Stopwatch();
    timer.start();//from   w w  w  .  jav  a 2  s  .c om
    MPurCalculator calculator = new MPurCalculator(reader, trainSize, beta, userBased, resBased);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
    List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
    if (trainSize == size) {
        trainSize = 0;
    }

    timer.reset();
    timer.start();
    for (int i = trainSize; i < size; i++) { // the test-set
        Bookmark data = reader.getBookmarks().get(i);
        Map<Integer, Double> map = calculator.getRankedTagList(data.getUserID(), data.getResourceID(), sorting);
        results.add(map);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);

    timeString = PerformanceMeasurement.addTimeMeasurement(timeString, true, trainingTime, testTime,
            sampleSize);
    return results;
}

From source file:org.litecoinj.crypto.MnemonicCode.java

/**
 * Convert mnemonic word list to seed./*  ww w  .  j av a2 s  .  c o  m*/
 */
public static byte[] toSeed(List<String> words, String passphrase) {

    // To create binary seed from mnemonic, we use PBKDF2 function
    // with mnemonic sentence (in UTF-8) used as a password and
    // string "mnemonic" + passphrase (again in UTF-8) used as a
    // salt. Iteration count is set to 4096 and HMAC-SHA512 is
    // used as a pseudo-random function. Desired length of the
    // derived key is 512 bits (= 64 bytes).
    //
    String pass = Utils.join(words);
    String salt = "mnemonic" + passphrase;

    final Stopwatch watch = Stopwatch.createStarted();
    byte[] seed = PBKDF2SHA512.derive(pass, salt, PBKDF2_ROUNDS, 64);
    watch.stop();
    log.info("PBKDF2 took {}", watch);
    return seed;
}

From source file:org.bitcoinj.crypto.MnemonicCode.java

/**
 * Convert mnemonic word list to seed.//from   ww  w  .j av a  2s . c o  m
 */
public static byte[] toSeed(List<String> words, String passphrase) {

    // To create binary seed from mnemonic, we use PBKDF2 function
    // with mnemonic sentence (in UTF-8) used as a password and
    // string "mnemonic" + passphrase (again in UTF-8) used as a
    // salt. Iteration count is set to 4096 and HMAC-SHA512 is
    // used as a pseudo-random function. Desired length of the
    // derived key is 512 bits (= 64 bytes).
    //
    String pass = Utils.SPACE_JOINER.join(words);
    String salt = "mnemonic" + passphrase;

    final Stopwatch watch = Stopwatch.createStarted();
    byte[] seed = PBKDF2SHA512.derive(pass, salt, PBKDF2_ROUNDS, 64);
    watch.stop();
    log.info("PBKDF2 took {}", watch);
    return seed;
}

From source file:processing.LanguageModelCalculator.java

public static List<Map<Integer, Double>> startLanguageModelCreation(BookmarkReader reader, int sampleSize,
        boolean sorting, boolean userBased, boolean resBased, int beta, boolean smoothing) {
    timeString = "";
    int size = reader.getUserLines().size();
    int trainSize = size - sampleSize;

    Stopwatch timer = new Stopwatch();
    timer.start();/*from ww w  .j  ava  2  s.  co  m*/
    LanguageModelCalculator calculator = new LanguageModelCalculator(reader, trainSize, beta, userBased,
            resBased);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
    List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
    if (trainSize == size) {
        trainSize = 0;
    }

    timer = new Stopwatch();
    timer.start();
    for (int i = trainSize; i < size; i++) { // the test-set
        UserData data = reader.getUserLines().get(i);
        Map<Integer, Double> map = calculator.getRankedTagList(data.getUserID(), data.getWikiID(), sorting,
                smoothing);
        results.add(map);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timeString += ("Full training time: " + trainingTime + "\n");
    timeString += ("Full test time: " + testTime + "\n");
    timeString += ("Average test time: " + testTime / (double) sampleSize) + "\n";
    timeString += ("Total time: " + (trainingTime + testTime) + "\n");
    return results;
}

From source file:processing.LayersCalculator.java

public static void predictSample(String filename, int trainSize, int sampleSize, int beta) {
    //filename += "_res";
    BookmarkReader reader = new BookmarkReader(trainSize, false);
    reader.readFile(filename);//from  www .j av  a 2  s  . c  om

    List<int[]> predictionValues = new ArrayList<int[]>();
    Stopwatch timer = new Stopwatch();
    timer.start();
    LayersCalculator calculator = new LayersCalculator(reader, trainSize, beta);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);

    timer = new Stopwatch();
    timer.start();
    for (int i = trainSize; i < trainSize + sampleSize; i++) { // the test-set
        UserData data = reader.getUserLines().get(i);
        Map<Integer, Double> map = calculator.getRankedTagList(data.getUserID(), data.getWikiID(),
                data.getCategories());
        predictionValues.add(Ints.toArray(map.keySet()));
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timeString += ("Full training time: " + trainingTime + "\n");
    timeString += ("Full test time: " + testTime + "\n");
    timeString += ("Average test time: " + testTime / (double) sampleSize) + "\n";
    timeString += ("Total time: " + (trainingTime + testTime) + "\n");
    String outputFile = filename + "_3layers";
    Utilities.writeStringToFile("./data/metrics/" + outputFile + "_TIME.txt", timeString);

    reader.setUserLines(reader.getUserLines().subList(trainSize, reader.getUserLines().size()));
    PredictionFileWriter writer = new PredictionFileWriter(reader, predictionValues);
    writer.writeFile(outputFile);
}

From source file:edu.mit.streamjit.test.apps.TriangleContainment.java

private static int runThreads() {
    Iterator<String> taskIterator = generateInput().iterator();
    AtomicInteger result = new AtomicInteger(0);
    List<Thread> threads = new ArrayList<>(NUM_THREADS);
    List<Semaphore> readSemaphores = new ArrayList<>(NUM_THREADS),
            writeSemaphores = new ArrayList<>(NUM_THREADS);
    for (int i = 0; i < NUM_THREADS; ++i) {
        readSemaphores.add(new Semaphore(i == 0 ? 1 : 0));
        writeSemaphores.add(new Semaphore(i == 0 ? 1 : 0));
    }// w w  w.j av  a  2  s.  c  o m
    for (int i = 0; i < NUM_THREADS; ++i)
        threads.add(new ComputeThread(taskIterator, result, readSemaphores.get(i),
                readSemaphores.get((i + 1) % readSemaphores.size()), writeSemaphores.get(i),
                writeSemaphores.get((i + 1) % writeSemaphores.size())));
    Stopwatch stopwatch = Stopwatch.createStarted();
    for (Thread t : threads)
        t.start();
    for (Thread t : threads)
        Uninterruptibles.joinUninterruptibly(t);
    System.out.println("Thread impl ran in " + stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
    return result.get();
}