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:eu.amidst.huginlink.examples.demos.ParallelTANDemo.java

public static void demoPigs() throws IOException, ClassNotFoundException {

    //It needs GBs, so avoid putting this file in a Dropbox folder!!
    //String dataFile = new String("/Users/afa/Pigs.arff");

    BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/dataWeka/Pigs.bn");

    int sampleSize = 10000;
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);

    ArrayList<Integer> vSamplesOnMemory = new ArrayList(Arrays.asList(5000));
    ArrayList<Integer> vNumCores = new ArrayList(Arrays.asList(1, 2, 3, 4));

    for (Integer samplesOnMemory : vSamplesOnMemory) {
        for (Integer numCores : vNumCores) {
            System.out.println(/*from   w w  w  . j  a v  a2 s . co  m*/
                    "Learning TAN: " + samplesOnMemory + " samples on memory, " + numCores + " core/s ...");
            DataStream<DataInstance> data = sampler.sampleToDataStream(sampleSize);

            ParallelTAN tan = new ParallelTAN();
            tan.setNumCores(numCores);
            tan.setNumSamplesOnMemory(samplesOnMemory);
            tan.setNameRoot(bn.getVariables().getListOfVariables().get(0).getName());
            tan.setNameTarget(bn.getVariables().getListOfVariables().get(1).getName());
            Stopwatch watch = Stopwatch.createStarted();
            BayesianNetwork model = tan.learn(data);
            System.out.println(watch.stop());
        }
    }
}

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

public static BugInstances initAndPerformAnalysis(IJavaProject javaProject, Reporter reporter,
        ConfigurationOptions configurationOptions) throws WALAInitializationException {
    BugInstances bugInstances = new BugInstances();
    int objectSensitivityLevel = configurationOptions.getObjectSensitivityLevel();
    reporter.report(new KeyValuePair("OBJECT_SENSITIVITY_LEVEL", String.valueOf(objectSensitivityLevel)));
    BasicAnalysisData basicAnalysisData = initBytecodeAnalysis(javaProject, reporter, configurationOptions);
    if (configurationOptions.shouldDumpCallGraph()) {
        dumpCallGraph(basicAnalysisData.callGraph);
    }/*  w  w  w . j a  va  2 s  .  co  m*/
    Iterator<BugPattern> bugPatternsIterator = BugPatterns.iterator();
    while (bugPatternsIterator.hasNext()) {
        BugPattern bugPattern = bugPatternsIterator.next();
        BugPatternDetector bugPatternDetector = bugPattern.createBugPatternDetector();
        Stopwatch stopWatch = Stopwatch.createStarted();
        BugInstances instancesOfCurrentBugPattern = bugPatternDetector.performAnalysis(javaProject,
                basicAnalysisData);
        stopWatch.stop();
        reporter.report(
                new KeyValuePair("BUG_PATTERN_" + bugPattern.getName() + "_DETECTION_TIME_IN_MILLISECONDS",
                        String.valueOf(stopWatch.elapsed(TimeUnit.MILLISECONDS))));
        bugInstances.addAll(instancesOfCurrentBugPattern);
        reporter.report(new KeyValuePair("NUMBER_OF_INSTANCES_OF_BUG_PATTERN_" + bugPattern.getName(),
                String.valueOf(instancesOfCurrentBugPattern.size())));
    }
    reporter.close();
    return bugInstances;
}

From source file:processing.ActCalculator.java

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

    Stopwatch timer = new Stopwatch();
    timer.start();//  w ww. java  2  s.  co m
    ActCalculator calculator = new ActCalculator(reader, trainSize, dVal, 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);
        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:com.codereligion.cherry.benchmark.BenchmarkRunner.java

public static Func1<Input, Observable<Output>> benchMark() {
    return new Func1<Input, Observable<Output>>() {
        @Override// w w w .  j  a v a  2 s  .  co  m
        public Observable<Output> call(final Input input) {
            final Output output = Output.from(input);

            output.withGuavaContestant(benchMark(input.getRepetitions(), input.getGuavaResult()));
            output.withCherryContestant(benchMark(input.getRepetitions(), input.getCherryResult()));

            return Observable.just(output);
        }

        private ContestantResult benchMark(final long repetitions, final Contestant contestant) {

            int checkInt = 0;
            final Stopwatch stopwatch = Stopwatch.createUnstarted();
            final ContestantResult contestantResult = ContestantResult.from(contestant);

            for (long reps = 0; reps < repetitions; reps++) {

                System.gc();
                stopwatch.start();
                checkInt |= contestant.run();
                stopwatch.stop();

                final long timeInNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
                contestantResult.addRunTime(timeInNanos);
                stopwatch.reset();
            }

            System.out.println("check int:" + checkInt);

            return contestantResult;
        }
    };
}

From source file:org.apache.tez.common.TezUtilsInternal.java

public static byte[] compressBytes(byte[] inBytes) throws IOException {
    Stopwatch sw = new Stopwatch().start();
    byte[] compressed = compressBytesInflateDeflate(inBytes);
    sw.stop();
    if (LOG.isDebugEnabled()) {
        LOG.debug("UncompressedSize: " + inBytes.length + ", CompressedSize: " + compressed.length
                + ", CompressTime: " + sw.elapsedMillis());
    }/*w  w  w.  j  av a 2 s. c  o m*/
    return compressed;
}

From source file:org.apache.tez.common.TezUtilsInternal.java

public static byte[] uncompressBytes(byte[] inBytes) throws IOException {
    Stopwatch sw = new Stopwatch().start();
    byte[] uncompressed = uncompressBytesInflateDeflate(inBytes);
    sw.stop();
    if (LOG.isDebugEnabled()) {
        LOG.debug("CompressedSize: " + inBytes.length + ", UncompressedSize: " + uncompressed.length
                + ", UncompressTimeTaken: " + sw.elapsedMillis());
    }/*from   w  w w. j  a v a 2  s.  c o m*/
    return uncompressed;
}

From source file:org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreHelper.java

public static void garbageReport(DocumentNodeStore dns) {
    System.out.print("Collecting top 100 nodes with most blob garbage ");
    Stopwatch sw = Stopwatch.createStarted();
    Iterable<BlobReferences> refs = scan(dns, new BlobGarbageSizeComparator(), 100);
    for (BlobReferences br : refs) {
        System.out.println(br);/*from   w  ww  . j  a v  a  2  s . co m*/
    }
    System.out.println("Collected in " + sw.stop());
}

From source file:org.opendaylight.yangtools.yang.parser.system.test.Main.java

private static void runSystemTest(final List<String> yangLibDirs, final List<String> yangFiles,
        final HashSet<QName> supportedFeatures, final boolean recursiveSearch) {
    LOG.log(Level.INFO, "Yang model dirs: {0} ", yangLibDirs);
    LOG.log(Level.INFO, "Yang model files: {0} ", yangFiles);
    LOG.log(Level.INFO, "Supported features: {0} ", supportedFeatures);

    SchemaContext context = null;//from w  ww.  j a va 2s. com

    printMemoryInfo("start");
    final Stopwatch stopWatch = Stopwatch.createStarted();

    try {
        context = SystemTestUtils.parseYangSources(yangLibDirs, yangFiles, supportedFeatures, recursiveSearch);
    } catch (final Exception e) {
        LOG.log(Level.SEVERE, "Failed to create SchemaContext.", e);
        System.exit(1);
    }

    stopWatch.stop();
    LOG.log(Level.INFO, "Elapsed time: {0}", stopWatch);
    printMemoryInfo("end");
    LOG.log(Level.INFO, "SchemaContext resolved Successfully. {0}", context);
    Runtime.getRuntime().gc();
    printMemoryInfo("after gc");
}

From source file:org.sonatype.sisu.bl.testsupport.DropwizardITSupport.java

protected static Stopwatch startBundle(final DropwizardBundle bundle) {
    final Stopwatch stopwatch = Stopwatch.createUnstarted();
    if (bundle != null && !bundle.isRunning()) {
        stopwatch.start();/* w ww .  j ava2s.c  o  m*/
        try {
            log.info("Starting DropWizard bundle ({})", bundle);
            bundle.start();
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
        stopwatch.stop();
    }
    return stopwatch;
}

From source file:org.sonatype.sisu.bl.servlet.jetty.testsuite.JettyITSupport.java

protected static Stopwatch startJetty(final JettyBundle jettyBundle) {
    final Stopwatch stopwatch = Stopwatch.createUnstarted();
    if (jettyBundle != null && !jettyBundle.isRunning()) {
        stopwatch.start();// www . jav  a2s .  c om
        try {
            LOGGER.info("Starting Jetty ({})", jettyBundle);
            jettyBundle.start();
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
        stopwatch.stop();
    }
    return stopwatch;
}