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

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

Introduction

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

Prototype

public void reset() 

Source Link

Document

Resets the stopwatch.

Usage

From source file:ubic.gemma.search.SearchServiceImpl.java

/**
 * @param classes/*ww  w  . j a v  a 2s .  c  o m*/
 * @param matches
 * @param query
 * @return
 */
private Collection<SearchResult> characteristicSearchWord(Collection<Class<?>> classes,
        Map<SearchResult, String> matches, String query) {

    StopWatch watch = startTiming();
    Collection<String> characteristicUris = new HashSet<String>();

    Collection<OntologyIndividual> individuals = ontologyService.findIndividuals(query);
    if (individuals.size() > 0 && watch.getTime() > 1000) {
        log.info("Found " + individuals.size() + " individuals matching '" + query + "' in " + watch.getTime()
                + "ms");
    }
    watch.reset();
    watch.start();

    for (OntologyIndividual term : individuals) {
        if ((term != null) && (term.getUri() != null))
            characteristicUris.add(term.getUri());
    }

    Collection<OntologyTerm> matchingTerms = ontologyService.findTerms(query);

    if (watch.getTime() > 1000) {
        log.info("Found " + matchingTerms.size() + " ontology classes matching '" + query + "' in "
                + watch.getTime() + "ms");
    }

    watch.reset();
    Collection<SearchResult> results = new HashSet<SearchResult>();
    Collection<Characteristic> cs = new HashSet<Characteristic>();
    if (!matchingTerms.isEmpty()) {
        watch.start();

        for (OntologyTerm term : matchingTerms) {
            String uri = term.getUri();
            if (uri == null || uri.isEmpty())
                continue;
            characteristicUris.add(uri);
            addChildTerms(characteristicUris, term);
        }

        // int cacheHits = childTermCache.getStatistics().getCacheHits();
        // if ( log.isDebugEnabled() ) log.debug( cacheHits + " cache hits for ontology children" );

        if (watch.getTime() > 1000) {
            log.info("Found " + characteristicUris.size() + " possible matches + child terms in "
                    + watch.getTime() + "ms");
        }

        /*
         * Find occurrences of these terms in our system. This is fast, so long as there aren't too many.
         */
        Collection<SearchResult> matchingCharacteristics = dbHitsToSearchResult(
                characteristicService.findByUri(classes, characteristicUris));

        for (SearchResult crs : matchingCharacteristics) {
            cs.add((Characteristic) crs.getResultObject());
        }
    }
    watch.reset();
    watch.start();
    /*
     * Add characteristics that have values matching the query; this pulls in items not associated with ontology
     * terms (free text). We do this here so we can apply the query logic to the matches.
     */
    String dbQueryString = query.replaceAll("\\*", "");
    Collection<Characteristic> valueMatches = characteristicService.findByValue(classes, dbQueryString);

    if (valueMatches != null && !valueMatches.isEmpty())
        cs.addAll(valueMatches);

    /*
     * Retrieve the owner objects
     */
    Collection<SearchResult> matchingEntities = getAnnotatedEntities(classes, cs);
    results.addAll(matchingEntities);

    if (watch.getTime() > 1000) {
        log.info("Slow search: found " + matchingEntities.size() + " matches to characteristics for '" + query
                + "' from " + characteristicUris.size() + " URIS in " + watch.getTime() + "ms");
    }

    watch.stop();

    for (SearchResult searchR : results) {
        if (!matches.containsKey(searchR)) {
            matches.put(searchR, query);
        } else {
            matches.put(searchR, matches.get(searchR) + " " + query);
        }
    }

    return results;
}

From source file:ubic.gemma.tasks.maintenance.IndexerTaskImpl.java

private Boolean rebuildIndex(CompassGpsInterfaceDevice device, String whatIndexingMsg) {

    StopWatch timer = new StopWatch();
    timer.start();/* www  . j  a  va2 s.  c  o  m*/
    log.info("Rebuilding " + whatIndexingMsg + ". First attempt.");

    Boolean success = CompassUtils.rebuildCompassIndex(device);

    // First attempt failed. Wait a bit then re-try.
    // See bug#2031. There are intermittent indexing failures. The cause is unknown at the moment.
    if (!success) {
        log.warn("Failed to index " + whatIndexingMsg + ". Trying it again...");
        try {
            Thread.sleep(120000); // sleep for 2 minutes.
        } catch (InterruptedException e) {
            log.warn("Job to index" + whatIndexingMsg + " was interrupted.");
            return false;
        }

        timer.reset();
        timer.start();
        log.info("Rebuilding " + whatIndexingMsg + ". Second attempt.");
        success = CompassUtils.rebuildCompassIndex(device);
    }

    // If failed for the second time send an email to administrator.
    if (!success) {
        mailEngine.sendAdminMessage("Failed to index " + whatIndexingMsg,
                "Failed to index " + whatIndexingMsg + ".  See logs for details");
        log.info("Failed rebuilding index for " + whatIndexingMsg + ".  Took (ms): " + timer.getTime());

    } else {
        log.info("Finished rebuilding " + whatIndexingMsg + ".  Took (ms): " + timer.getTime());
    }

    return success;

}

From source file:ubic.pubmedgate.loader.PubMedLoadFromXML.java

/**
 * Just loads all from the XML files (use on test XML directory)
 * /*  w  ww  .j a  v a  2 s . com*/
 * @throws Exception
 */
public void runAllTest() throws Exception {
    StopWatch watch = new StopWatch();
    watch.start();
    List<BibliographicReference> XMLloadedRefs = getRefs();
    log.info("Got refs:" + watch.getTime());
    watch.reset();
    watch.start();
    loadRefs(XMLloadedRefs, p2g.getUnseenCorp());
    log.info("Time to load refs:" + watch.getTime());
    log.info("Found in XML size:" + XMLloadedRefs.size());
    log.info("Corpus size:" + p2g.getUnseenCorp().size());
}

From source file:uk.ac.cam.eng.rule.retrieval.HFileRuleQuery.java

@SuppressWarnings("unchecked")
@Override//from   w  w w.  j  a va2  s.  co m
public void run() {
    List<Text> sortedQuery = new ArrayList<>(query);
    query.clear();
    StopWatch stopWatch = new StopWatch();
    System.out.println("Sorting query");
    stopWatch.start();
    Collections.sort(sortedQuery, new MergeComparator());
    System.out.printf("Query sort took %d seconds\n", stopWatch.getTime() / 1000);
    stopWatch.reset();
    stopWatch.start();
    try {
        for (Text source : sortedQuery) {
            SidePattern sourcePattern = SidePattern.getPattern(source.toString());

            tempOut.reset();
            source.write(tempOut);
            if (!bf.contains(tempOut.getData(), 0, tempOut.getLength(), null)) {
                continue;
            }
            if (reader.seek(source)) {
                if (retriever.testVocab.contains(source)) {
                    synchronized (retriever.foundTestVocab) {
                        retriever.foundTestVocab.add(source);
                    }
                }
                Set<RuleWritable> existingRules = new HashSet<>();
                List<Pair<RuleWritable, AlignmentAndFeatureMap>> allFiltered = new ArrayList<>();
                List<String> provenances = new ArrayList<>();
                provenances.add("");
                provenances.addAll(conf.getStringCollection(ProvenanceCountMap.PROV));
                for (String provenance : provenances) {
                    if (!retriever.filter.isProvenanceUnion() && !provenance.equals("")) {
                        continue;
                    }
                    SortedSet<Pair<RuleWritable, AlignmentAndFeatureMap>> rules = new TreeSet<Pair<RuleWritable, AlignmentAndFeatureMap>>(
                            retriever.filter.getComparator(provenance));
                    for (Pair<RuleWritable, AlignmentAndFeatureMap> entry : reader.getRulesForSource()) {
                        RuleWritable rule = entry.getFirst();
                        AlignmentAndFeatureMap rawFeatures = entry.getSecond();
                        if (retriever.filter.filterRule(sourcePattern, rule, rawFeatures.getSecond(),
                                provenance)) {
                            continue;
                        }
                        rules.add(Pair.createPair(new RuleWritable(rule), rawFeatures));
                    }
                    List<Pair<RuleWritable, AlignmentAndFeatureMap>> filtered = retriever.filter
                            .filterRulesBySource(sourcePattern, rules, provenance);
                    for (Pair<RuleWritable, AlignmentAndFeatureMap> ruleFiltered : filtered) {
                        if (!existingRules.contains(ruleFiltered.getFirst())) {
                            allFiltered.add(ruleFiltered);
                            existingRules.add(ruleFiltered.getFirst());
                        }
                    }
                }
                queue.addAll(allFiltered);
                if (queue.size() > BATCH_SIZE) {
                    drainQueue();
                }

            }

        }
        drainQueue();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.out.printf("Query took %d seconds\n", stopWatch.getTime() / 1000);

}

From source file:velo.scripting.ScriptingManager.java

public static void main(String[] args) throws FactoryException {
    //ScriptingManager sm = new ScriptingManager();
    //ScriptEngine se = sm.getScriptEngine("groovy");
    ScriptEngine se = ScriptingManager.getScriptEngine("groovy");

    OperationContext oc = new OperationContext();
    se.put("name", "moshe");
    se.put("cntx", oc);
    //String a = "<?xml version=\"1.0\"?><j:jelly trim=\"false\" xmlns:j=\"jelly:core\" xmlns:x=\"jelly:xml\" xmlns:html=\"jelly:html\"><html><head><title>${name}'s Page</title></head></html></j:jelly>";
    //String a = "def a = new Date(); println(a.getClass().getName()); def myArr = new Date[1]; myArr[0] = a; println(myArr.getClass().getName()); cntx.addVar('myArr',myArr);";
    String a = "def a = new Date(); a.getClass().getName(); def myArr = new Date[1]; myArr[0] = a; myArr.getClass().getName(); cntx.addVar('myArr',myArr);";

    //Sadly it seems that invoking via se.eval and script.eval almost return the same times, thought it should be much more effecient :/
    try {//from  ww w .  j  a  v a  2s .c o  m
        //groovy
        //se.eval("println(name);");
        StopWatch sw = new StopWatch();
        sw.start();

        for (int i = 0; i < 100000; i++) {
            se.eval(a);
        }
        sw.stop();
        System.out.println("time in seconds: '" + sw.getTime() / 1000 + "'");
        sw.reset();

        sw.start();
        CompiledScript script = ((Compilable) se).compile(a);
        for (int i = 0; i < 100000; i++) {
            script.eval();
        }
        sw.stop();
        System.out.println("time in seconds: '" + sw.getTime() / 1000 + "'");

        OperationContext getOc = (OperationContext) se.get("cntx");
        Date[] arrOfDate = (Date[]) getOc.get("myArr");
        //System.out.println(arrOfDate);

    } catch (ScriptException e) {
        System.out.println("ERROR: " + e);
    }
}