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

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

Introduction

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

Prototype

public StopWatch() 

Source Link

Document

Constructor.

Usage

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

private void queryMutations() {
    List<Long> ids = new ArrayList<Long>();
    for (Mutation m : getMutations()) {
        ids.add(m.getId());//from   ww  w .ja  v  a 2s .  c om
    }
    StringBuilder sb = new StringBuilder();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    List<Mutation> mutations = QueryManager.getMutationsByIds(ids.toArray(new Long[0]));
    for (Mutation mutation : mutations) {
        sb.append(mutation.getClassName());
    }
    stopWatch.stop();
    System.out.printf("Querying %d mutations took %s -- checkvalue: %d\n", LIMIT,
            DurationFormatUtils.formatDurationHMS(stopWatch.getTime()), sb.length());
}

From source file:com.liferay.wiki.util.WikiCacheHelper.java

public WikiPageDisplay getDisplay(long nodeId, String title, PortletURL viewPageURL,
        Supplier<PortletURL> editPageURLSupplier, String attachmentURLPrefix) {

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();/*from ww  w .j a va 2s  .  c o m*/

    String key = _encodeKey(nodeId, title, viewPageURL.toString());

    WikiPageDisplay pageDisplay = (WikiPageDisplay) _portalCache.get(key);

    if (pageDisplay == null) {
        pageDisplay = _getPageDisplay(nodeId, title, viewPageURL, editPageURLSupplier.get(),
                attachmentURLPrefix);

        if (pageDisplay != null) {
            PortalCacheHelperUtil.putWithoutReplicator(_portalCache, key, pageDisplay);
        }
    }

    if (_log.isDebugEnabled()) {
        _log.debug(StringBundler.concat("getDisplay for {", String.valueOf(nodeId), ", ", title, ", ",
                String.valueOf(viewPageURL), ", ", String.valueOf(editPageURLSupplier.get()), "} takes ",
                String.valueOf(stopWatch.getTime()), " ms"));
    }

    return pageDisplay;
}

From source file:adams.gui.tools.wekainvestigator.tab.clustertab.evaluation.AbstractClustererEvaluation.java

/**
 * Evaluates the clusterer and updates the result item.
 *
 * @param clusterer   the current clusterer
 * @param item   the item to update//ww  w  .  j  a  v  a  2s.c o m
 * @throws Exception   if evaluation fails
 */
public void evaluate(Clusterer clusterer, ResultItem item) throws Exception {
    StopWatch watch;

    watch = new StopWatch();
    watch.start();
    doEvaluate(clusterer, item);
    watch.stop();
    if (item.hasRunInformation())
        item.getRunInformation().add("Total time", (watch.getTime() / 1000.0) + "s");
}

From source file:net.nan21.dnet.core.web.controller.data.AbstractDsRpcController.java

/**
 * Default handler for remote procedure call on a single value-object.
 * //from   ww w .ja  v a 2s  .  com
 * @param resourceName
 * @param dataformat
 * @param dataString
 * @param paramString
 * @return
 * @throws Exception
 */
@RequestMapping(params = { Constants.REQUEST_PARAM_ACTION + "=" + Constants.DS_ACTION_RPC,
        Constants.DS_ACTION_RPC + "Type=data" })
@ResponseBody
public String rpcData(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_SERVICE_NAME_PARAM, required = true) String rpcName,
        @RequestParam(value = Constants.REQUEST_PARAM_DATA, required = false, defaultValue = "{}") String dataString,
        @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {}-data / {}",
                    new String[] { resourceName, dataFormat, Constants.DS_ACTION_RPC, rpcName });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-data: {} ", new String[] { dataString });
            logger.debug("  --> request-params: {} ", new String[] { paramString });
        }

        this.prepareRequest(request, response);

        this.authorizeDsAction(resourceName, Constants.DS_ACTION_RPC, rpcName);

        if (dataFormat.equals("stream")) {
            IDsService<M, F, P> service = this.findDsService(resourceName);
            IDsMarshaller<M, F, P> marshaller = service.createMarshaller("json");

            M data = marshaller.readDataFromString(dataString);
            P params = marshaller.readParamsFromString(paramString);

            InputStream s = service.rpcDataStream(rpcName, data, params);
            this.sendFile(s, response.getOutputStream());
            return "";
        } else {
            IDsService<M, F, P> service = this.findDsService(resourceName);
            IDsMarshaller<M, F, P> marshaller = service.createMarshaller(dataFormat);

            M data = marshaller.readDataFromString(dataString);
            P params = marshaller.readParamsFromString(paramString);

            service.rpcData(rpcName, data, params);
            IActionResultRpcData result = this.packRpcDataResult(data, params);
            stopWatch.stop();
            result.setExecutionTime(stopWatch.getTime());
            return marshaller.writeResultToString(result);
        }

    } catch (Exception e) {
        return this.handleException(e, response);
    } finally {
        this.finishRequest();
    }
}

From source file:adams.gui.tools.wekainvestigator.tab.associatetab.evaluation.AbstractAssociatorEvaluation.java

/**
 * Evaluates the associator and updates the result item.
 *
 * @param associator   the current associator
 * @param item   the item to update/*from  www  . j av  a2 s  .  c o  m*/
 * @throws Exception   if evaluation fails
 */
public void evaluate(Associator associator, ResultItem item) throws Exception {
    StopWatch watch;

    watch = new StopWatch();
    watch.start();
    doEvaluate(associator, item);
    watch.stop();
    if (item.hasRunInformation())
        item.getRunInformation().add("Total time", (watch.getTime() / 1000.0) + "s");
}

From source file:com.mothsoft.alexis.engine.textual.TopicDocumentMatcherImpl.java

public void execute() {

    logger.info("Starting Topic<=>Document Matching");

    final StopWatch stopWatch = new StopWatch();

    // a unique state for documents pending matching so we can transition
    // items that had no topics (prevent a big future spike when a topic is
    // added that now matches really old documents)
    stopWatch.start();//from   w ww  .  j a  v a 2s  .c  o m
    bulkUpdateDocumentState(DocumentState.PARSED, DocumentState.PENDING_TOPIC_MATCHING);
    stopWatch.stop();
    logger.info("Marking PARSED documents as PENDING_TOPIC_MATCHING took: " + stopWatch.toString());
    stopWatch.reset();

    stopWatch.start();
    match();
    stopWatch.stop();
    logger.info("Matching documents and topics took: " + stopWatch.toString());
    stopWatch.reset();

    // update any documents that had no assignments
    stopWatch.start();
    bulkUpdateDocumentState(DocumentState.PENDING_TOPIC_MATCHING, DocumentState.MATCHED_TO_TOPICS);
    stopWatch.stop();
    logger.info("Marking PENDING_TOPIC_MATCHING documents as MATCHED_TO_TOPICS took: " + stopWatch.toString());
}

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

public static void deleteResults(Session session, Query q) {
    @SuppressWarnings("unchecked")
    List<Mutation> mutations = q.list();
    int deletes = 0, flushs = 0;
    StopWatch stp = new StopWatch();
    for (Mutation m : mutations) {
        MutationTestResult result = m.getMutationResult();
        if (result != null) {
            m.setMutationResult(null);//from  w  ww . j  av  a  2  s  .  co m
            session.delete(result);
            deletes++;
        }
        if (deletes > 20) {
            // 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()));
            deletes = 0;
        }
    }
    logger.info(String.format("Deleted %d mutation results", mutations.size()));
}

From source file:com.qualogy.qafe.gwt.server.processor.impl.EventProcessorImpl.java

public GDataObject execute(EventDataGVO eventData, ApplicationIdentifier appId,
        SessionContainer sessionContainer) {

    ApplicationContext context = ApplicationCluster.getInstance().get(appId);
    EventHandler eventHandler = context.getEventHandler();

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from  w  w  w.  ja v a  2 s  .c om

    GDataObject data = new GDataObject();
    data.setSenderId(eventData.getSender());
    data.setListenerType(eventData.getListenerType());
    data.setEventId(eventData.getEventId());
    data.setUuid(eventData.getUuid());
    data.setParent(eventData.getParent());
    ApplicationStoreIdentifier appStoreId = new ApplicationStoreIdentifier(eventData.getUuid());
    String[] senderInfo = StringUtils.split(eventData.getSender(), '|');
    logger.fine(eventData.toString() + ", WindowID " + senderInfo[1]);

    String windowId = "";
    if (senderInfo.length == 2 || senderInfo.length == 3) {
        if (senderInfo.length == 2) {// dealing with a RootPanel only
            windowId = senderInfo[0];
        }
        if (senderInfo.length == 3) {

            windowId = senderInfo[1];
        }
        try {

            List<InputVariable> inputVariables = new ArrayList<InputVariable>();

            if (eventData.getInputVariables() != null && eventData.getInputVariables().size() > 0) {
                for (InputVariableGVO inVar : eventData.getInputVariables()) {
                    inputVariables.add(
                            new InputVariable(inVar.getName(), inVar.getReference(), inVar.getDefaultValue(),
                                    inVar.getComponentValue(), convert(inVar.getDataContainerObject())));
                }
            }

            EventDataObject eventDataObject = new EventDataObject(eventData.getEventId(),
                    eventData.getSourceInfo(), appId, eventData.getListenerType(), inputVariables,
                    eventData.getInternalVariables(), senderInfo[0], eventData.getSenderName(), windowId,
                    eventData.getUuid(), eventData.getUserUID(), eventData.getWindowSession(),
                    eventData.getRequest(), eventData.getParameters(), eventData.getMouse());
            eventDataObject.setApplicationStoreIdentifier(appStoreId);

            Collection<?> builtInFunctionsToExecute = eventHandler.manage(eventDataObject);
            Iterator<?> itr = builtInFunctionsToExecute.iterator();
            Collection<BuiltInFunctionGVO> builtInFunctions = new ArrayList<BuiltInFunctionGVO>();
            while (itr.hasNext()) {
                BuiltInFunction builtInFunctionToExecute = (BuiltInFunction) itr.next();
                BuiltInFunctionGVO builtInFunction = EventUIAssembler
                        .convert((EventItem) builtInFunctionToExecute, eventData, context, sessionContainer);
                if (builtInFunction != null) {
                    builtInFunctions.add(builtInFunction);
                }
            }
            data.setFunctions((BuiltInFunctionGVO[]) builtInFunctions.toArray(new BuiltInFunctionGVO[] {}));
        } catch (RuntimeException e) {
            ExceptionHelper.printStackTrace(e);
            throw e;

        } catch (ExternalException e) {
            ExceptionHelper.printStackTrace(e.getCause());
            throw new RuntimeException(e.getMessage(), e);
        }
    } else {
        logger.warning("Error in sender string (is not partionable in size 2) : " + eventData.getSender());
    }
    stopWatch.stop();

    logger.warning("EventProcessorImpl uuid:[" + eventData.getUuid() + "], sender[" + eventData.getSender()
            + "], eventId [" + eventData.getEventName() + "]  took  [" + stopWatch.getTime() + "]ms ");
    return data;
}

From source file:com.couchbase.graph.CBGraphPerfTest.java

/**
 * To add 1000 vertices/*  w  ww . ja va2s . c o m*/
 */
@Test
@RunIf(value = PerfEnabledChecker.class)
public void testAdd1000Vertices() {
    System.out.println("-- testAdd1000Vertices");

    //Generate some random id-s
    String[] uuids = new String[1000];

    for (int i = 0; i < 1000; i++) {

        String uuid = UUID.randomUUID().toString();
        uuids[i] = uuid;
    }

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

    //For each UUID add a vertex

    for (String uuid : uuids) {

        graph.addVertex(uuid);
    }

    sw.stop();

    System.out.println("1000 verices added in " + sw.getTime() + " ms");

    System.out.println("- Proof that the last one was added");
    Vertex v = graph.getVertex(uuids[uuids.length - 1]);
    assertNotNull(v);

}

From source file:com.cedarsoft.serialization.SplittingPerformanceRunner.java

private static void run(@Nonnull String description, @Nonnull Callable<String> callable) throws Exception {
    //Warmup/*from w w w  .  ja v a  2 s. c om*/
    for (int i = 0; i < 1000; i++) {
        assertEquals("1.0.0", callable.call());
    }

    //Do the work
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    for (int i = 0; i < 100000; i++) {
        assertEquals("1.0.0", callable.call());
    }

    stopWatch.stop();
    System.out.println(description + " took " + stopWatch.getTime());
}