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:com.davidbracewell.math.linear.MatrixMath.java

/**
 * The entry point of application.//from  www  .  jav  a2s.  com
 *
 * @param args the input arguments
 * @throws Exception the exception
 */
public static void main(String[] args) throws Exception {
    Matrix m1 = randomMatrix(10000, 10000);
    Matrix m2 = randomMatrix(10000, 10000);

    Stopwatch sw = Stopwatch.createStarted();
    Matrix m3 = m1.multiply(m2);
    sw.stop();
    System.out.println(sw);

    //    System.out.println(m3);
    //
    //    m1 = new SparseMatrix(2, 3);
    //    m1.set(0, 0, 1);
    //    m1.set(0, 1, 2);
    //    m1.set(0, 2, 3);
    //    m1.set(1, 0, 4);
    //    m1.set(1, 1, 5);
    //    m1.set(1, 2, 6);
    //
    //    m2 = new SparseMatrix(3, 2);
    //    m2.set(0, 0, 7);
    //    m2.set(0, 1, 8);
    //    m2.set(1, 0, 9);
    //    m2.set(1, 1, 10);
    //    m2.set(2, 0, 11);
    //    m2.set(2, 1, 12);
    //
    //    m3 = m1.multiply(m2);
    //    System.out.println(m3);

}

From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.Main.java

public static void main(String[] args) {
    try {//from w  w w  .j a  va2s .  co m
        Map<Command, Optional<String>> cmds = Command.parse(args);
        if ((cmds.containsKey(Command.HELP)) || (!cmds.containsKey(Command.CONFIG))) {
            usage();
            return;
        }
        final JDBCConfig config = config(cmds.get(Command.CONFIG).get());

        String pwd = config.password.orNull();
        if (null == pwd) {
            Optional<String> opt = passwordOf("database", config.user);
            if (!opt.isPresent()) {
                throw new ExitException(RetCode.ERR_CANCELLED);
            }
            pwd = opt.get();
        }
        try (JDBCConnection from = create(config, pwd); CSVWriter writer = makeLog(config.user)) {
            Stopwatch watch = Stopwatch.createStarted();
            Stores stores = StoresReader.STORESREADER.apply(from);
            System.out.println("spent " + watch.stop() + " to load stores");
            final Function<DecoratedContent, Checks.Result> checker = Checks.checker(stores);
            final Multiset<Checks.Code> codes = TreeMultiset.create();
            watch.reset().start();
            ResponseUI rui = ResponseUI.create(1024, 64);
            try (CloseableIterator<DecoratedContent> it = DCReader.reader(from, stores)) {
                long count = 0L;
                while (it.hasNext()) {
                    DecoratedContent dc = it.next();
                    count++;
                    final Checks.Result result = checker.apply(dc);
                    assert null != result;
                    rui.onResponse(result);
                    final Checks.Code code = result.code;
                    codes.add(code);
                    if (code != Checks.Code.OK) {
                        // we've got an error then ....
                        writer.writeError(dc, result);
                    }
                }
                rui.finish();
                System.out.println("spent " + watch.stop() + " to read " + count + " d.c.");
                System.out.println("stats: " + codes);
                System.out.println("bye");
            }
        }
    } catch (SQLException e) {
        e.printStackTrace(System.err);
        System.err.flush();
        System.out.println();
        usage();
        System.exit(RetCode.ERR_SQL.ordinal());
    } catch (ExitException e) {
        e.exit();
    } catch (RuntimeException | IOException e) {
        e.printStackTrace(System.err);
        System.err.flush();
        System.out.println();
        usage();
        System.exit(RetCode.ERR_OTHER.ordinal());
    }
}

From source file:com.doctor.getting_started.UsingJava8BetterByUseMethodReference.java

public static void main(String[] args) {
    ExecutorService executor = Executors.newCachedThreadPool();
    int ringBufferSize = 1024;

    Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, ringBufferSize, executor);
    disruptor.handleEventsWith(UsingJava8BetterByUseMethodReference::onEvent);
    disruptor.start();//w w w . java 2  s.  co m

    ByteBuffer buffer = ByteBuffer.allocate(8);

    Stopwatch stopwatch = Stopwatch.createStarted();

    for (long i = 0; i < 10; i++) {
        buffer.putLong(0, i);
        disruptor.publishEvent(UsingJava8BetterByUseMethodReference::translateTo, buffer);
    }

    long elapsed = stopwatch.elapsed(TimeUnit.MICROSECONDS);
    System.out.println("elapsed:" + elapsed);
    stopwatch.stop();

    disruptor.shutdown();
    executor.shutdown();
}

From source file:eu.amidst.huginlink.learning.ParallelPC.java

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

    OptionParser.setArgsOptions(ParallelPC.class, args);

    BayesianNetworkGenerator.loadOptions();

    BayesianNetworkGenerator.setNumberOfGaussianVars(0);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(100, 10);
    BayesianNetworkGenerator.setSeed(0);

    BayesianNetwork bn = BayesianNetworkGenerator.generateNaiveBayes(2);

    int sampleSize = 5000;
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);
    sampler.loadOptions();//  w  w  w .jav a2s  .  co m

    DataStream<DataInstance> data = sampler.sampleToDataStream(sampleSize);

    for (int i = 1; i <= 4; i++) {
        int samplesOnMemory = 1000;
        int numCores = i;
        System.out
                .println("Learning PC: " + samplesOnMemory + " samples on memory, " + numCores + "core/s ...");
        ParallelPC parallelPC = new ParallelPC();
        parallelPC.setOptions(args);
        //tan.loadOptionsFromFile("configurationFiles/conf.txt");
        parallelPC.setNumCores(numCores);
        parallelPC.setNumSamplesOnMemory(samplesOnMemory);
        Stopwatch watch = Stopwatch.createStarted();
        BayesianNetwork model = parallelPC.learn(data);
        System.out.println(watch.stop());
    }
}

From source file:org.hyperledger.perftest.PerfTestApp.java

public static void main(String[] args) throws Exception {
    Stopwatch watch = Stopwatch.createStarted();
    System.setProperty("logback.configurationFile", "logback.xml");
    int rounds = Integer.parseInt(args[2]);
    int count = Integer.parseInt(args[3]);
    //        int threadCount = Integer.parseInt(args[4]);
    int threadCount = 1;
    PerfTestApp app = new PerfTestApp(rounds, count, threadCount);
    app.measure(app.bcsapi);//w  w  w  .j a  va  2s .  c om
    app.stop();
    watch.stop();
    System.out.println("DONE in " + watch.elapsed(TimeUnit.SECONDS) + " seconds");
    System.exit(0);
}

From source file:eu.amidst.huginlink.learning.ParallelTAN.java

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

    OptionParser.setArgsOptions(ParallelTAN.class, args);

    BayesianNetworkGenerator.loadOptions();

    BayesianNetworkGenerator.setNumberOfGaussianVars(0);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(2000, 10);
    BayesianNetworkGenerator.setSeed(0);

    BayesianNetwork bn = BayesianNetworkGenerator.generateNaiveBayes(2);

    int sampleSize = 5000;
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);
    sampler.loadOptions();//from w w w . ja  v  a  2  s . c  om

    DataStream<DataInstance> data = sampler.sampleToDataStream(sampleSize);

    for (int i = 1; i <= 4; i++) {
        int samplesOnMemory = 1000;
        int numCores = i;
        System.out
                .println("Learning TAN: " + samplesOnMemory + " samples on memory, " + numCores + "core/s ...");
        ParallelTAN tan = new ParallelTAN();
        tan.setOptions(args);
        //tan.loadOptionsFromFile("configurationFiles/conf.txt");
        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:com.couchbase.roadrunner.RoadRunner.java

/**
 * Initialize the RoadRunner./*  ww  w.  j a  va2s  .c  o  m*/
 *
 * This method is responsible for parsing the passed in command line arguments
 * and also dispatch the bootstrapping of the actual workload runner.
 *
 * @param args Command line arguments to be passed in.
 */
public static void main(final String[] args) {
    CommandLine params = null;
    try {
        params = parseCommandLine(args);
    } catch (ParseException ex) {
        LOGGER.error("Exception while parsing command line!", ex);
        System.exit(-1);
    }

    if (params.hasOption(OPT_HELP)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("roadrunner", getCommandLineOptions());
        System.exit(0);
    }

    GlobalConfig config = GlobalConfig.fromCommandLine(params);
    WorkloadDispatcher dispatcher = new WorkloadDispatcher(config);

    LOGGER.info("Running with Config: " + config.toString());

    try {
        LOGGER.debug("Initializing ClientHandlers.");
        dispatcher.init();
    } catch (Exception ex) {
        LOGGER.error("Error while initializing the ClientHandlers: ", ex);
        System.exit(-1);
    }

    Stopwatch workloadStopwatch = new Stopwatch().start();
    try {
        LOGGER.info("Running Workload.");
        dispatcher.dispatchWorkload();
    } catch (Exception ex) {
        LOGGER.error("Error while running the Workload: ", ex);
        System.exit(-1);
    }
    workloadStopwatch.stop();

    LOGGER.debug("Finished Workload.");

    LOGGER.info("==== RESULTS ====");

    dispatcher.prepareMeasures();

    long totalOps = dispatcher.getTotalOps();
    long measuredOps = dispatcher.getMeasuredOps();

    LOGGER.info("Operations: measured " + measuredOps + "ops out of total " + totalOps + "ops.");

    Map<String, List<Stopwatch>> measures = dispatcher.getMeasures();
    for (Map.Entry<String, List<Stopwatch>> entry : measures.entrySet()) {
        Histogram h = new Histogram(60 * 60 * 1000, 5);
        for (Stopwatch watch : entry.getValue()) {
            h.recordValue(watch.elapsed(TimeUnit.MICROSECONDS));
        }

        LOGGER.info("Percentile (microseconds) for \"" + entry.getKey() + "\" Workload:");
        LOGGER.info("   50%:" + (Math.round(h.getValueAtPercentile(0.5) * 100) / 100) + "   75%:"
                + (Math.round(h.getValueAtPercentile(0.75) * 100) / 100) + "   95%:"
                + (Math.round(h.getValueAtPercentile(0.95) * 100) / 100) + "   99%:"
                + (Math.round(h.getValueAtPercentile(0.99) * 100) / 100));
    }

    LOGGER.info("Elapsed: " + workloadStopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms");

    List<Stopwatch> elapsedThreads = dispatcher.getThreadElapsed();
    long shortestThread = 0;
    long longestThread = 0;
    for (Stopwatch threadWatch : elapsedThreads) {
        long threadMs = threadWatch.elapsed(TimeUnit.MILLISECONDS);
        if (longestThread == 0 || threadMs > longestThread) {
            longestThread = threadMs;
        }
        if (shortestThread == 0 || threadMs < shortestThread) {
            shortestThread = threadMs;
        }
    }

    LOGGER.info("Shortest Thread: " + shortestThread + "ms");
    LOGGER.info("Longest Thread: " + longestThread + "ms");

}

From source file:eu.amidst.core.inference.messagepassing.ParallelVMP.java

public static void main(String[] arguments) throws IOException, ClassNotFoundException {

    BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/Munin1.bn");
    System.out.println(bn.getNumberOfVars());
    System.out.println(bn.getConditionalDistributions().stream().mapToInt(p -> p.getNumberOfParameters()).max()
            .getAsInt());//from  ww w  .  j  av a2  s  .  co m

    ParallelVMP vmp = new ParallelVMP();

    InferenceEngine.setInferenceAlgorithm(vmp);
    Variable var = bn.getVariables().getVariableById(0);
    UnivariateDistribution uni = null;

    double avg = 0;
    for (int i = 0; i < 20; i++) {
        Stopwatch watch = Stopwatch.createStarted();
        uni = InferenceEngine.getPosterior(var, bn);
        System.out.println(watch.stop());
        avg += watch.elapsed(TimeUnit.MILLISECONDS);
    }
    System.out.println(avg / 20);
    System.out.println(uni);

}

From source file:eu.amidst.core.utils.BayesianNetworkSampler.java

public static void main(String[] args) throws Exception {

    Stopwatch watch = Stopwatch.createStarted();

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

    BayesianNetworkSampler sampler = new BayesianNetworkSampler(network);
    sampler.setSeed(0);/*  w ww . j a  v a2s.co m*/

    DataStream<DataInstance> dataStream = sampler.sampleToDataStream(100);

    DataStreamWriter.writeDataToFile(dataStream, "./datasets/simulated/asisa-samples.arff");

    System.out.println(watch.stop());

    for (Assignment assignment : sampler.getSampleIterator(10)) {
        System.out.println(assignment.outputString());
    }
    System.out.println();

    for (Assignment assignment : sampler.getSampleList(2)) {
        System.out.println(assignment.outputString());
    }
    System.out.println();

    sampler.getSampleStream(2).forEach(e -> System.out.println(e.outputString()));
}

From source file:pocman.demo.ClosedCPPDemo.java

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

    final Stopwatch stopwatch = new Stopwatch();

    final ClosedCPPDemo that = new ClosedCPPDemo(MATCHING_ALGORITHM_1);

    for (final String level : Mazes.LEVELS) {
        final int pocManPosition = level.indexOf(Tile.POCMAN.toCharacter());
        Preconditions.checkState(pocManPosition > -1, "POCMAN POSITION NOT FOUND !");
        final char[] data = level.toCharArray();
        data[pocManPosition] = Tile.COIN.toCharacter();

        final Maze maze = Maze.from(data);

        stopwatch.start();//from  w  ww.ja v a  2s  .c o  m
        final ClosedCPPSolution<MazeNode> closedCPPSolution = that.solve(maze);
        stopwatch.stop();

        final EulerianTrailInterface<MazeNode> eulerianTrailInterface = maze.get()
                .fetch(EulerianTrailFeature.class).up();
        final List<MazeNode> closedTrail = eulerianTrailInterface.getEulerianTrail(maze.getNode(pocManPosition),
                closedCPPSolution.getTraversalByEdge()); // TODO ! maze.getEulerianTrail(startingMazeNode)

        that.debug(maze, closedTrail, 160);
        System.out.println(closedCPPSolution);
        Thread.sleep(1000);

        /*
        stopwatch.start();
        final OpenCPPSolution<MazeNode> openCPPSolution = that.solve(closedCPPSolution, maze.getNode(pocManPosition));
        stopwatch.stop();
                
        final List<MazeNode> trail = EulerianTrail.from(
            openCPPSolution.getGraph(),
            openCPPSolution.getTraversalByEdge(),
            openCPPSolution.getEndPoint());
                
        that.debug(maze, trail, 160);
        */

        //break;
    }

    /*
    stopwatch.start();
    final OpenCPPSolution<MazeNode> openCPPSolution = that.solve(closedCPPSolution, maze.getNode(pocManPosition));
    stopwatch.stop();
            
    final List<MazeNode> trail = EulerianTrail.from(
        openCPPSolution.getGraph(),
        openCPPSolution.getTraversalByEdge(),
        openCPPSolution.getEndPoint());
            
    that.debug(maze, trail, 320);
    System.out.println(openCPPSolution);
    Thread.sleep(1000);
    */

    //}

    System.out.println(stopwatch.elapsedTime(TimeUnit.MILLISECONDS) + " " + TimeUnit.MILLISECONDS.toString());
}