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:hr.fer.tel.rovkp.homework02.task01.Program.java

public static void main(String[] args) throws Exception {
    Stopwatch timer = new Stopwatch();
    timer.start();/* w w  w.  j  a va 2s  . co  m*/

    if (args.length != 2) {
        timer.stop();
        System.err.println("Usage: <jar> <input path> <output path>");
        return;
    }

    Job job = Job.getInstance();
    job.setJarByClass(Program.class);
    job.setJobName("TripTimes");

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    job.setMapperClass(TripTimesMapper.class);
    // job.setCombinerClass(TripTimesReducer.class);
    job.setReducerClass(TripTimesReducer.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(TripTimesTuple.class);

    // job.setNumReduceTasks(1);

    job.waitForCompletion(true);
    timer.stop();
    System.out.println("Total time: " + timer.elapsedTime(TimeUnit.SECONDS) + "s");
}

From source file:de.jamilsoufan.panalyzer.app.Panalyzer.java

/**
 * Entry point of the application//  w ww . j  a  v  a2s. co  m
 *
 * @param args Command line arguments
 */
public static void main(String[] args) {
    LOGGER.info("Starting panalyzer for: {}", Analyzer.START_DIR);
    Stopwatch stopwatch = Stopwatch.createStarted();

    Runner runnner = new Runner();
    runnner.runForrestRun();

    stopwatch.stop();
    LOGGER.info("Finish. Analyzed folders: {} / files: {}. Duration: {}", Analyzer.countFolders,
            Analyzer.countFiles, stopwatch);
}

From source file:com.sri.ai.distributed.experiment.SimpleExperiment.java

public static void main(String[] args) {
    String cnfFileName = args[0];
    DIMACSReader dimacsReader = new SimplifiedDIMACSReader();

    CNFProblem cnfProblem = dimacsReader.read(cnfFileName);

    cnfProblem.getClauses().cache();/*from   w  ww . ja va2s  .  co  m*/

    System.out.println("# variables        = " + cnfProblem.getNumberVariables());
    System.out.println("# clauses reported = " + cnfProblem.getNumberClauses() + ", number clauses loaded = "
            + cnfProblem.getClauses().count());

    Stopwatch sw = new Stopwatch();

    sw.start();
    SATSolver solver = newSolver();
    int[] model = solver.findModel(cnfProblem);
    sw.stop();

    System.out.println("Took " + sw);

    if (model == null) {
        System.out.println("Problem is NOT satisfiable");
    } else {
        StringJoiner sj = new StringJoiner(", ");
        for (int i = 0; i < model.length; i++) {
            sj.add("" + model[i]);
        }

        System.out.println("Problem is satisfiable, example model found:" + sj);
    }
}

From source file:ninja.vertx.Benchmarker.java

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

    // spin up standalone, but don't join
    Standalone standalone = new NinjaVertx()
            //        Standalone standalone = new NinjaJetty()
            .externalConfigurationPath("conf/vertx.example.conf")
            .port(StandaloneHelper.findAvailablePort(8000, 9000)).start();
    final int requests = 100000;
    final int threads = 1000;

    final OkHttpClient client = NinjaOkHttp3Tester.newHttpClientBuilder()
            .connectionPool(new ConnectionPool(threads, 60000L, TimeUnit.MILLISECONDS)).build();

    final AtomicInteger requested = new AtomicInteger();

    /**//from   ww  w  .jav a  2 s . c o m
    // get request w/ parameters
    final Request request
    = requestBuilder(standalone, "/parameters?a=joe&c=cat&d=dog&e=egg&f=frank&g=go")
        .header("Cookie", "TEST=THISISATESTCOOKIEHEADER")
        .build();
    */

    // json request w/ parameters
    byte[] json = "{ \"s\":\"string\", \"i\":2 }".getBytes(Charsets.UTF_8);
    final Request request = requestBuilder(standalone, "/benchmark_json?a=joe&c=cat&d=dog&e=egg&f=frank&g=go")
            .header("Cookie", "TEST=THISISATESTCOOKIEHEADER")
            .post(RequestBody.create(MediaType.parse("application/json"), json)).build();

    /**
    final Request request
    = requestBuilder(standalone, "/benchmark_form?a=joe&c=cat&d=dog&e=egg&f=frank&g=go")
        .post(new FormBody.Builder()
            .add("a", "frank")
            .add("b", "2")
            .add("h", "hello")
            .add("z", "zulu")
            .build())
        .build();
    */

    // warmup
    for (int i = 0; i < 100; i++) {
        Response response = executeRequest(client, request);
        response.body().close();
    }

    final CountDownLatch startSignal = new CountDownLatch(1);
    final CountDownLatch doneSignal = new CountDownLatch(threads);
    ExecutorService threadPool = Executors.newFixedThreadPool(threads);

    for (int i = 0; i < threads; i++) {
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    startSignal.await();
                    while (requested.incrementAndGet() < requests) {
                        Response response = executeRequest(client, request);
                        response.body().close();
                    }
                    doneSignal.countDown();
                } catch (InterruptedException | IOException e) {
                    log.error("", e);
                }
            }
        });
    }

    // real
    Stopwatch stopwatch = Stopwatch.createStarted();
    startSignal.countDown();
    doneSignal.await();
    stopwatch.stop();
    log.info("Took {} ms for {} requests", stopwatch.elapsed(TimeUnit.MILLISECONDS), requests);
    logMemory();

    standalone.shutdown();
    threadPool.shutdown();
}

From source file:ninja.undertow.Benchmarker.java

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

    // spin up standalone, but don't join
    Standalone standalone = new NinjaUndertow()
            //Standalone standalone = new NinjaJetty()
            .externalConfigurationPath("conf/undertow.example.conf")
            .port(StandaloneHelper.findAvailablePort(8000, 9000)).start();

    final int requests = 100000;
    final int threads = 50;

    final OkHttpClient client = NinjaOkHttp3Tester.newHttpClientBuilder()
            .connectionPool(new ConnectionPool(threads, 60000L, TimeUnit.MILLISECONDS)).build();

    final AtomicInteger requested = new AtomicInteger();

    /**/*from w w w  .j  a  v  a 2 s .  c om*/
    // get request w/ parameters
    final Request request
    = requestBuilder(standalone, "/parameters?a=joe&c=cat&d=dog&e=egg&f=frank&g=go")
        .header("Cookie", "TEST=THISISATESTCOOKIEHEADER")
        .build();
    */

    // json request w/ parameters
    byte[] json = "{ \"s\":\"string\", \"i\":2 }".getBytes(Charsets.UTF_8);
    final Request request = requestBuilder(standalone, "/benchmark_json?a=joe&c=cat&d=dog&e=egg&f=frank&g=go")
            .header("Cookie", "TEST=THISISATESTCOOKIEHEADER")
            .post(RequestBody.create(MediaType.parse("application/json"), json)).build();

    /**
    final Request request
    = requestBuilder(standalone, "/benchmark_form?a=joe&c=cat&d=dog&e=egg&f=frank&g=go")
        .post(new FormBody.Builder()
            .add("a", "frank")
            .add("b", "2")
            .add("h", "hello")
            .add("z", "zulu")
            .build())
        .build();
    */

    // warmup
    for (int i = 0; i < 100; i++) {
        Response response = executeRequest(client, request);
        response.body().close();
    }

    final CountDownLatch startSignal = new CountDownLatch(1);
    final CountDownLatch doneSignal = new CountDownLatch(threads);
    ExecutorService threadPool = Executors.newFixedThreadPool(threads);

    for (int i = 0; i < threads; i++) {
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    startSignal.await();
                    while (requested.incrementAndGet() < requests) {
                        Response response = executeRequest(client, request);
                        response.body().close();
                    }
                    doneSignal.countDown();
                } catch (InterruptedException | IOException e) {
                    log.error("", e);
                }
            }
        });
    }

    // real
    Stopwatch stopwatch = Stopwatch.createStarted();
    startSignal.countDown();
    doneSignal.await();
    stopwatch.stop();
    log.info("Took {} ms for {} requests", stopwatch.elapsed(TimeUnit.MILLISECONDS), requests);
    logMemory();

    standalone.shutdown();
    threadPool.shutdown();
}

From source file:eu.amidst.huginlink.examples.learning.ParallelPCExample.java

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

    //We load a Bayesian network to generate a data stream
    //using BayesianNewtorkSampler class.
    int sampleSize = 100000;
    BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/dataWeka/Pigs.bn");
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);

    //We fix the number of samples in memory used for performing the structural learning.
    //They are randomly sub-sampled using Reservoir sampling.
    int samplesOnMemory = 5000;

    //We make different trials with different number of cores
    ArrayList<Integer> vNumCores = new ArrayList(Arrays.asList(1, 2, 3, 4));

    for (Integer numCores : vNumCores) {
        System.out/*from w  w  w .  ja va  2 s .  c  o  m*/
                .println("Learning PC: " + samplesOnMemory + " samples on memory, " + numCores + " core/s ...");
        DataStream<DataInstance> data = sampler.sampleToDataStream(sampleSize);

        //The class ParallelTAN is created
        ParallelPC parallelPC = new ParallelPC();

        //We activate the parallel mode.
        parallelPC.setParallelMode(true);

        //We set the number of cores to be used for the structural learning
        parallelPC.setNumCores(numCores);

        //We set the number of samples to be used for the learning the structure
        parallelPC.setNumSamplesOnMemory(samplesOnMemory);

        Stopwatch watch = Stopwatch.createStarted();

        //We just invoke this mode to learn a BN model for the data stream
        BayesianNetwork model = parallelPC.learn(data);

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

From source file:de.seekircher.techsummit.client.Main.java

public static void main(String[] args) {
    DemoClient client = new DemoClient();
    Stopwatch stopwatch = new Stopwatch();

    for (int i = 0; i < NUM_ITERATIONS; i++) {
        stopwatch.reset().start();/*from  www  .  ja va  2  s .  c  o m*/
        String response = client.echo("Norbert", DELAY_TIME_SECS, true);

        System.out.println(String.format("Response after %d msecs: %s",
                stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), response));
    }
}

From source file:eu.amidst.huginlink.examples.learning.ParallelTANExample.java

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

    //We load a Bayesian network to generate a data stream
    //using BayesianNewtorkSampler class.
    int sampleSize = 100000;
    BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/dataWeka/Pigs.bn");
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);

    //We fix the number of samples in memory used for performing the structural learning.
    //They are randomly sub-sampled using Reservoir sampling.
    int samplesOnMemory = 5000;

    //We make different trials with different number of cores
    ArrayList<Integer> vNumCores = new ArrayList(Arrays.asList(1, 2, 3, 4));

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

        //The class ParallelTAN is created
        ParallelTAN tan = new ParallelTAN();

        //We activate the parallel mode.
        tan.setParallelMode(true);

        //We set the number of cores to be used for the structural learning
        tan.setNumCores(numCores);

        //We set the number of samples to be used for the learning the structure
        tan.setNumSamplesOnMemory(samplesOnMemory);

        //We set the root variable to be first variable
        tan.setNameRoot(bn.getVariables().getListOfVariables().get(0).getName());

        //We set the class variable to be the last variable
        tan.setNameTarget(bn.getVariables().getListOfVariables()
                .get(bn.getVariables().getListOfVariables().size() - 1).getName());

        Stopwatch watch = Stopwatch.createStarted();

        //We just invoke this mode to learn the TAN model for the data stream
        BayesianNetwork model = tan.learn(data);

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

From source file:grakn.core.server.Grakn.java

public static void main(String[] args) {
    Thread.setDefaultUncaughtExceptionHandler(
            (Thread t, Throwable e) -> LOG.error(ErrorMessage.UNCAUGHT_EXCEPTION.getMessage(t.getName()), e));

    try {//from   w  w w.j  a  va 2  s.  c  o m
        String graknPidFileProperty = Optional.ofNullable(SystemProperty.GRAKN_PID_FILE.value()).orElseThrow(
                () -> new RuntimeException(ErrorMessage.GRAKN_PIDFILE_SYSTEM_PROPERTY_UNDEFINED.getMessage()));

        Path pidfile = Paths.get(graknPidFileProperty);
        PIDManager pidManager = new PIDManager(pidfile);
        pidManager.trackGraknPid();

        // Start Server with timer
        Stopwatch timer = Stopwatch.createStarted();
        boolean benchmark = parseBenchmarkArg(args);
        Server server = ServerFactory.createServer(benchmark);
        server.start();

        LOG.info("Grakn started in {}", timer.stop());
    } catch (RuntimeException | IOException e) {
        LOG.error(ErrorMessage.UNCAUGHT_EXCEPTION.getMessage(e.getMessage()), e);
        System.err.println(ErrorMessage.UNCAUGHT_EXCEPTION.getMessage(e.getMessage()));
    }
}

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

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

    BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/dataWeka/Munin1.bn");
    System.out.println(bn.getNumberOfVars());
    System.out.println(bn.getDAG().getNumberOfLinks());
    System.out.println(bn.getConditionalDistributions().stream().mapToInt(p -> p.getNumberOfParameters()).max()
            .getAsInt());/*w w w. j  av  a 2 s .c o  m*/

    VMP vmp = new VMP();
    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);

}