Example usage for org.apache.commons.lang.time StopWatch getTime

List of usage examples for org.apache.commons.lang.time StopWatch getTime

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch getTime.

Prototype

public long getTime() 

Source Link

Document

Get the time on the stopwatch.

This is either the time between the start and the moment this method is called, or the amount of time between start and stop.

Usage

From source file:fr.inria.edelweiss.kgdqp.core.FedQueryingCLI.java

@SuppressWarnings("unchecked")
public static void main(String args[]) throws ParseException, EngineException {

    List<String> endpoints = new ArrayList<String>();
    String queryPath = null;//from  w w  w  . j  av  a2 s  .  c o m
    int slice = -1;

    Options options = new Options();
    Option helpOpt = new Option("h", "help", false, "print this message");
    Option queryOpt = new Option("q", "query", true, "specify the sparql query file");
    Option endpointOpt = new Option("e", "endpoints", true, "the list of federated sparql endpoint URLs");
    Option groupingOpt = new Option("g", "grouping", true, "triple pattern optimisation");
    Option slicingOpt = new Option("s", "slicing", true, "size of the slicing parameter");
    Option versionOpt = new Option("v", "version", false, "print the version information and exit");
    options.addOption(queryOpt);
    options.addOption(endpointOpt);
    options.addOption(helpOpt);
    options.addOption(versionOpt);
    options.addOption(groupingOpt);
    options.addOption(slicingOpt);

    String header = "Corese/KGRAM DQP command line interface";
    String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr";

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("kgdqp", header, options, footer, true);
        System.exit(0);
    }
    if (!cmd.hasOption("e")) {
        logger.info("You must specify at least the URL of one sparql endpoint !");
        System.exit(0);
    } else {
        endpoints = new ArrayList<String>(Arrays.asList(cmd.getOptionValues("e")));
    }
    if (!cmd.hasOption("q")) {
        logger.info("You must specify a path for a sparql query !");
        System.exit(0);
    } else {
        queryPath = cmd.getOptionValue("q");
    }
    if (cmd.hasOption("s")) {
        try {
            slice = Integer.parseInt(cmd.getOptionValue("s"));
        } catch (NumberFormatException ex) {
            logger.warn(cmd.getOptionValue("s") + " is not formatted as number for the slicing parameter");
            logger.warn("Slicing disabled");
        }
    }
    if (cmd.hasOption("v")) {
        logger.info("version 3.0.4-SNAPSHOT");
        System.exit(0);
    }

    /////////////////
    Graph graph = Graph.create();
    QueryProcessDQP exec = QueryProcessDQP.create(graph);
    exec.setGroupingEnabled(cmd.hasOption("g"));
    if (slice > 0) {
        exec.setSlice(slice);
    }
    Provider sProv = ProviderImplCostMonitoring.create();
    exec.set(sProv);

    for (String url : endpoints) {
        try {
            exec.addRemote(new URL(url), WSImplem.REST);
        } catch (MalformedURLException ex) {
            logger.error(url + " is not a well-formed URL");
            System.exit(1);
        }
    }

    StringBuffer fileData = new StringBuffer(1000);
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(queryPath));
    } catch (FileNotFoundException ex) {
        logger.error("Query file " + queryPath + " not found !");
        System.exit(1);
    }
    char[] buf = new char[1024];
    int numRead = 0;
    try {
        while ((numRead = reader.read(buf)) != -1) {
            String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);
            buf = new char[1024];
        }
        reader.close();
    } catch (IOException ex) {
        logger.error("Error while reading query file " + queryPath);
        System.exit(1);
    }

    String sparqlQuery = fileData.toString();

    //        Query q = exec.compile(sparqlQuery, null);
    //        System.out.println(q);

    StopWatch sw = new StopWatch();
    sw.start();
    Mappings map = exec.query(sparqlQuery);
    int dqpSize = map.size();
    System.out.println("--------");
    long time = sw.getTime();
    System.out.println(time + " " + dqpSize);
}

From source file:com.eaio.uuid.UUIDPerformance.java

public static void main(String[] args) {

    Thread[] threads = new Thread[Runtime.getRuntime().availableProcessors()];

    for (int i = 0; i < threads.length; ++i) {
        threads[i] = new Thread(new UUIDRunnable(count / threads.length));
    }/*ww w  .  jav a  2 s.co  m*/

    StopWatch watch = new StopWatch();
    watch.start();

    for (Thread t : threads) {
        t.start();
    }

    for (Thread t : threads) {
        try {
            t.join();
        } catch (InterruptedException e) {
            // Moo
        }
    }

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

From source file:com.liferay.portal.tools.DBUpgrader.java

public static void main(String[] args) {
    try {//w ww.  j  a v a 2 s . c o  m
        StopWatch stopWatch = new StopWatch();

        stopWatch.start();

        InitUtil.initWithSpring();

        upgrade();
        verify();

        System.out.println("\nSuccessfully completed upgrade process in " + (stopWatch.getTime() / Time.SECOND)
                + " seconds.");

        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();

        System.exit(1);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    StopWatch clock = new StopWatch();
    NumberFormat format = NumberFormat.getInstance();

    System.out.println("How long does it take to take the sin of 0.34 ten million times?");
    clock.start();//from w w  w .j  a v a 2s.  com
    for (int i = 0; i < 100000000; i++) {
        Math.sin(0.34);
    }
    clock.stop();

    System.out.println("It takes " + clock.getTime() + " milliseconds");

    System.out.println("How long does it take to multiply 2 doubles one billion times?");
    clock.reset();
    clock.start();
    for (int i = 0; i < 1000000000; i++) {
        double result = 3423.2234 * 23e-4;
    }
    clock.stop();
    System.out.println("It takes " + clock.getTime() + " milliseconds.");

    System.out.println("How long does it take to add 2 ints one billion times?");
    clock.reset();
    clock.start();
    for (int i = 0; i < 1000000000; i++) {
        int result = 293842923 + 33382922;
    }
    clock.stop();
    System.out.println("It takes " + clock.getTime() + " milliseconds.");

    System.out.println("Testing the split() method.");
    clock.reset();
    clock.start();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    clock.split();
    System.out.println("Split Time after 1 sec: " + clock.getTime());
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Split Time after 2 sec: " + clock.getTime());
    clock.unsplit();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Time after 3 sec: " + clock.getTime());

}

From source file:de.tudarmstadt.ukp.dkpro.core.frequency.util.ProviderBenchmark.java

public static void main(String[] args) throws Exception {
    Web1TProviderBase web1t = new Web1TFileAccessProvider(args);
    Corpus brown = new BrownTeiCorpus();

    StopWatch watch = new StopWatch();
    watch.start();/*from   w w w . j  a  v  a  2s . co m*/
    watch.suspend();

    for (Text text : brown.getTexts()) {
        for (Sentence s : text.getSentences()) {
            for (String t : s.getTokens()) {
                watch.resume();
                web1t.getFrequency(t);
                watch.suspend();
            }
        }
    }

    double time = (double) watch.getTime() / 1000;
    System.out.println(time + "s");
}

From source file:MainClass.java

public static void main(String[] args) {
    StopWatch stWatch = new StopWatch();

    //Start StopWatch
    stWatch.start();/*from  w  w  w . j av  a2  s.  c om*/

    //Get iterator for all days in a week starting Monday
    Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY);

    while (itr.hasNext()) {
        Calendar gCal = (Calendar) itr.next();
        System.out.println(gCal.getTime());
    }

    //Stop StopWatch
    stWatch.stop();
    System.out.println("Time Taken >>" + stWatch.getTime());

}

From source file:TimeTrial.java

public static void main(String[] args) {

    StopWatch stWatch = new StopWatch();

    // Start StopWatch
    stWatch.start();/*from w  w w .  ja v  a 2  s  .  c o  m*/

    // Get iterator for all days in a week starting Monday
    Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY);

    while (itr.hasNext()) {
        Calendar gCal = (Calendar) itr.next();
        System.out.println(gCal.getTime());
    }

    // Stop StopWatch
    stWatch.stop();
    System.out.println("Time Taken >>" + stWatch.getTime());

}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.IndexCreationUtil.java

public static void main(final String[] args) throws Exception {
    Parameters parameters = null;//from   w  w w  . ja  v  a2s .c  om
    try {
        parameters = new Parameters(args);
    } catch (IllegalArgumentException e) {
        System.out.println(Parameters.getUsage());
        System.exit(1);
        return; // for Eclipse
    }
    LogInitializer.init();
    String databaseKind = parameters.getDatabaseKind();
    String duplicatedDatabaseKind = parameters.getDuplicatedDatabaseKind();
    String indexFolder = parameters.getIndexFolder();
    if (duplicatedDatabaseKind != null) {

        String databaseName = DATABASE_NAME_PREFIX + databaseKind;
        String duplicatedDatabaseName = DATABASE_NAME_PREFIX + duplicatedDatabaseKind;
        boolean ok = duplicateDatabase(duplicatedDatabaseName, databaseName);
        if (ok == false) {
            System.exit(1);
        }
        File dumpFile = parameters.getDumpFile();
        operationLog.info("Dump '" + duplicatedDatabaseName + "' into '" + dumpFile + "'.");
        DumpPreparator.createDatabaseDump(duplicatedDatabaseName, dumpFile);
        databaseKind = duplicatedDatabaseKind;
        FileUtilities.deleteRecursively(new File(indexFolder));
    }
    System.setProperty("database.kind", databaseKind);
    // Deactivate the indexing in the application context loaded by Spring.
    System.setProperty("hibernate.search.index-mode", "NO_INDEX");
    System.setProperty("hibernate.search.index-base", indexFolder);
    System.setProperty("database.create-from-scratch", "false");
    hibernateSearchContext = createHibernateSearchContext(indexFolder);
    hibernateSearchContext.afterPropertiesSet();
    operationLog.info("=========== Start indexing ===========");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    performFullTextIndex();
    stopWatch.stop();
    operationLog.info("Index of database '" + DATABASE_NAME_PREFIX + databaseKind + "' successfully built in '"
            + indexFolder + "' after " + ((stopWatch.getTime() + 30000) / 60000) + " minutes.");
    System.exit(0);
}

From source file:de.unisb.cs.st.javalanche.mutation.util.FilePerformanceTest.java

public static void main(String[] args) throws IOException {
    int limit = 1000;
    int total = 0;
    StopWatch stp = new StopWatch();
    stp.start();//from  w  ww . ja va 2  s .c  om
    File dir = new File("mutation-files/tmp");
    dir.mkdir();
    for (int i = 0; i < limit; i++) {
        Map<String, Set<Integer>> map = getMap();
        File tempFile = new File(dir, "test-" + i + ".ser");
        if (!tempFile.exists()) {
            SerializeIo.serializeToFile(map, tempFile);
        } else {
            Map<String, Set<Integer>> deserialize = SerializeIo.get(tempFile);
            total += deserialize.size();
        }
    }
    System.out.println(
            "Handling " + limit + " files took " + DurationFormatUtils.formatDurationHMS(stp.getTime()));
}

From source file:de.unisb.cs.st.javalanche.mutation.util.CsvWriter.java

public static void main(String[] args) throws IOException {
    // Set<Long> covered = MutationCoverageFile.getCoveredMutations();
    // List<Long> mutationIds = QueryManager.getMutationsWithoutResult(
    // covered, 0);

    Session session = HibernateUtil.getSessionFactory().openSession();
    List<Mutation> mutations = QueryManager.getMutationsForProject(
            ConfigurationLocator.getJavalancheConfiguration().getProjectPrefix(), session);

    logger.info("Got " + mutations.size() + " mutation ids.");
    List<String> lines = new ArrayList<String>();
    lines.add(Mutation.getCsvHead() + ",DETECTED");
    int counter = 0;
    int flushs = 0;
    StopWatch stp = new StopWatch();
    for (Mutation mutation : mutations) {
        // Mutation mutation = QueryManager.getMutationByID(id, session);
        lines.add(mutation.getCsvString() + "," + mutation.isKilled());
        counter++;/*from  www  .  j  a  va 2 s .co  m*/
        if (counter > 20) {
            counter = 0;
            // 20, same as the JDBC batch size
            // flush a batch of inserts and release memory:
            // see
            // http://www.hibernate.org/hib_docs/reference/en/html/batch.html
            stp.reset();
            stp.start();
            flushs++;
            session.flush();
            // session.clear();
            logger.info("Did flush. It took: " + DurationFormatUtils.formatDurationHMS(stp.getTime()));
        }
    }
    session.close();
    logger.info("Starting to write file with " + lines.size() + " entries.");
    FileUtils.writeLines(new File("mutations.csv"), lines);
}