Example usage for org.springframework.util StopWatch start

List of usage examples for org.springframework.util StopWatch start

Introduction

In this page you can find the example usage for org.springframework.util StopWatch start.

Prototype

public void start() throws IllegalStateException 

Source Link

Document

Start an unnamed task.

Usage

From source file:com.github.totyumengr.minicubes.core.MiniCubeTest.java

@Test
public void test_5_1_Distinct_20140606() throws Throwable {

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1);
    Map<Integer, RoaringBitmap> distinct = miniCube.distinct("postId", true, "tradeId", filter);
    stopWatch.stop();/*from w ww.j a  v a 2s . co m*/

    Assert.assertEquals(210, distinct.size());
    Assert.assertEquals(3089, distinct.get(1601).getCardinality());
    Assert.assertEquals(1825, distinct.get(1702).getCardinality());
    Assert.assertEquals(2058, distinct.get(-2).getCardinality());

    LOGGER.info(stopWatch.getTotalTimeSeconds() + " used for distinct result {}", distinct.toString());
}

From source file:com.github.totyumengr.minicubes.core.MiniCubeTest.java

@Test
public void test_5_2_DistinctCount_20140606() throws Throwable {

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1);
    filter.put("tradeId", Arrays.asList(
            new Integer[] { 3205, 3206, 3207, 3208, 3209, 3210, 3212, 3299, 3204, 3203, 3202, 3201, 3211 }));
    Map<Integer, RoaringBitmap> distinct = miniCube.distinct("postId", true, "tradeId", filter);
    stopWatch.stop();/*ww  w .java2  s .c o  m*/

    Assert.assertEquals(13, distinct.size());
    Assert.assertEquals(277, distinct.get(3209).getCardinality());
    Assert.assertEquals(186, distinct.get(3211).getCardinality());
    Assert.assertEquals(464, distinct.get(3206).getCardinality());
    LOGGER.info(stopWatch.getTotalTimeSeconds() + " used for distinct result {}", distinct.toString());

}

From source file:ch.silviowangler.dox.LoadIntegrationTest.java

@Test
@Ignore("Needs rework since it produces unreliable results")
public void testQuery() throws Exception {

    StopWatch stopWatch = new StopWatch();

    Map<TranslatableKey, DescriptiveIndex> indices = new HashMap<>();

    TranslatableKey company = new TranslatableKey("company");
    indices.put(company, new DescriptiveIndex("3?"));

    stopWatch.start();
    Set<DocumentReference> invoices = documentService.findDocumentReferences(indices, "INVOICE");
    stopWatch.stop();/*from w ww . j  a v  a 2  s  .  c  o m*/

    final long totalTimeMillis = stopWatch.getTotalTimeMillis();
    assertTrue("This test may take only " + TOTAL_AMOUNT_OF_TIME_IN_MILLIS + " ms but took this time "
            + totalTimeMillis + " ms", totalTimeMillis <= TOTAL_AMOUNT_OF_TIME_IN_MILLIS);

    for (DocumentReference documentReference : invoices) {
        String value = documentReference.getIndices().get(company).toString();
        assertTrue("Value is wrong: " + value, value.matches("(3|3\\d)"));
    }
    assertThat(invoices.size(), is(11));
}

From source file:my.adam.smo.server.HTTPServer.java

@Inject
public HTTPServer(@Value("${server_worker_threads:10}") int workerCount) {
    bootstrap.setFactory(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
            Executors.newCachedThreadPool(), workerCount));

    ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
        @Override/* w  w  w  .j av  a 2 s . c  o  m*/
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline p = Channels.pipeline();

            if (enableTrafficLogging) {
                InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
                p.addLast("logger", new LoggingHandler(InternalLogLevel.DEBUG));
            }

            p.addLast("codec", new HttpServerCodec());
            p.addLast("chunkAggregator", new HttpChunkAggregator(MAX_CONTENT_LENGTH));
            p.addLast("chunkedWriter", new ChunkedWriteHandler());
            p.addLast("compressor", new HttpContentCompressor());

            p.addLast("handler", new SimpleChannelUpstreamHandler() {
                @Override
                public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) throws Exception {
                    StopWatch stopWatch = new StopWatch("messageReceived");
                    stopWatch.start();

                    final DefaultHttpRequest httpRequest = (DefaultHttpRequest) e.getMessage();
                    ChannelBuffer cb = Base64.decode(httpRequest.getContent(), Base64Dialect.STANDARD);

                    RPCommunication.Request request = RPCommunication.Request
                            .parseFrom(cb.copy(0, cb.readableBytes()).array());
                    logger.trace("received request:" + request.toString());

                    if (enableAsymmetricEncryption) {
                        request = getAsymDecryptedRequest(request);
                        logger.trace("asymmetric encryption enabled, decrypted request: " + request.toString());
                    }

                    if (enableSymmetricEncryption) {
                        request = getDecryptedRequest(request);
                        logger.trace("symmetric encryption enabled, decrypted request: " + request.toString());
                    }

                    final RPCommunication.Request protoRequest = request;

                    RpcController dummyController = new DummyRpcController();
                    Service service = serviceMap.get(request.getServiceName());

                    logger.trace("got service: " + service + " for name " + request.getServiceName());

                    Descriptors.MethodDescriptor methodToCall = service.getDescriptorForType()
                            .findMethodByName(request.getMethodName());

                    logger.trace("got method: " + methodToCall + " for name " + request.getMethodName());

                    Message methodArguments = service.getRequestPrototype(methodToCall).newBuilderForType()
                            .mergeFrom(request.getMethodArgument()).build();

                    logger.trace("get method arguments from request " + methodArguments.toString());

                    RpcCallback<Message> callback = new RpcCallback<Message>() {
                        @Override
                        public void run(Message parameter) {
                            HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
                                    HttpResponseStatus.OK);

                            ByteArrayOutputStream paramOutputStream = new ByteArrayOutputStream();
                            CodedOutputStream paramCodedOutputStream = CodedOutputStream
                                    .newInstance(paramOutputStream);
                            try {
                                parameter.writeTo(paramCodedOutputStream);
                                paramCodedOutputStream.flush();
                            } catch (IOException e1) {
                                logger.error("failed to write to output stream");
                            }

                            RPCommunication.Response response = RPCommunication.Response.newBuilder()
                                    .setResponse(ByteString.copyFrom(paramOutputStream.toByteArray()))
                                    .setRequestId(protoRequest.getRequestId()).build();

                            if (enableSymmetricEncryption) {
                                response = getEncryptedResponse(response);
                                logger.trace("symmetric encryption enabled, encrypted response: "
                                        + response.toString());
                            }

                            if (enableAsymmetricEncryption) {
                                response = getAsymEncryptedResponse(response);
                                logger.trace("asymmetric encryption enabled, encrypted response: "
                                        + response.toString());
                            }

                            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                            CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(outputStream);
                            try {
                                response.writeTo(codedOutputStream);
                                codedOutputStream.flush();
                            } catch (IOException e1) {
                                logger.error("unable to write to output stream", e1);
                            }

                            byte[] arr = outputStream.toByteArray();

                            ChannelBuffer resp = Base64.encode(ChannelBuffers.copiedBuffer(arr),
                                    Base64Dialect.STANDARD);

                            httpResponse.setContent(resp);
                            httpResponse.addHeader(HttpHeaders.Names.CONTENT_LENGTH, resp.readableBytes());
                            httpResponse.addHeader(HttpHeaders.Names.CONTENT_TYPE,
                                    HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);

                            e.getChannel().write(httpResponse);
                            logger.trace("finishing call, httpResponse sent");
                        }
                    };
                    logger.trace("calling " + methodToCall.getFullName());
                    service.callMethod(methodToCall, dummyController, methodArguments, callback);
                    stopWatch.stop();
                    logger.trace(stopWatch.shortSummary());
                }

                @Override
                public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
                    if (!standardExceptionHandling(ctx, e)) {
                        super.exceptionCaught(ctx, e);
                    }
                }
            });
            return p;
        }
    };
    bootstrap.setPipelineFactory(pipelineFactory);
}

From source file:org.sventon.cache.direntrycache.DirEntryCacheUpdater.java

/**
 * Updates the cache with the given revisions.
 *
 * @param revisionUpdate The updated revisions.
 *///from w w  w .j  a v a  2s  .  c o  m
public void update(final RevisionUpdate revisionUpdate) {
    final RepositoryName repositoryName = revisionUpdate.getRepositoryName();

    LOGGER.info("Listener got [" + revisionUpdate.getRevisions().size()
            + "] updated revision(s) for repository: " + repositoryName);

    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    SVNConnection connection = null;

    try {
        final DirEntryCache entryCache = cacheManager.getCache(repositoryName);
        final RepositoryConfiguration configuration = application.getConfiguration(repositoryName);
        connection = connectionFactory.createConnection(repositoryName, configuration.getSVNURL(),
                configuration.getCacheCredentials());
        updateInternal(entryCache, connection, revisionUpdate);
    } catch (final Exception ex) {
        LOGGER.warn("Could not update cache instance [" + repositoryName + "]", ex);
    } finally {
        if (connection != null) {
            connection.closeSession();
        }
    }

    stopWatch.stop();
    LOGGER.info("Update completed in [" + stopWatch.getTotalTimeSeconds() + "] seconds");
}

From source file:org.dd4t.core.filters.impl.DefaultLinkResolverFilter.java

protected void resolveComponentLinkField(ComponentLinkField componentLinkField) {

    StopWatch stopWatch = null;
    if (logger.isDebugEnabled()) {
        stopWatch = new StopWatch();
        stopWatch.start();
    }/*from   w w  w .  j av  a2 s  . co m*/
    List<Object> compList = componentLinkField.getValues();

    for (Object component : compList) {
        resolveComponent((GenericComponent) component);
    }

    if (logger.isDebugEnabled()) {
        stopWatch.stop();
        logger.debug("Resolved componentLinkField '" + componentLinkField.getName() + "' in "
                + stopWatch.getTotalTimeMillis() + " ms.");
    }

}

From source file:org.dd4t.core.filters.impl.DefaultLinkResolverFilter.java

protected void resolvePage(GenericPage page) {

    StopWatch stopWatch = null;
    if (logger.isDebugEnabled()) {
        stopWatch = new StopWatch();
        stopWatch.start();
    }//w w w. ja v a  2  s  . c o  m

    List<ComponentPresentation> cpList = page.getComponentPresentations();
    if (cpList != null) {
        for (ComponentPresentation cp : cpList) {
            resolveComponent((GenericComponent) cp.getComponent(), page);
        }
    }
    resolveMap(page.getMetadata());

    if (logger.isDebugEnabled()) {
        stopWatch.stop();
        logger.debug(
                "ResolvePage for " + page.getId() + " finished in " + stopWatch.getTotalTimeMillis() + " ms");
    }
}

From source file:org.impalaframework.extension.mvc.flash.FlashStateEnabledAnnotationHandlerAdapter.java

public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    RequestModelHelper.maybeDebugRequest(logger, request);

    StopWatch watch = null;

    final boolean debugEnabled;

    if (logger.isDebugEnabled()) {
        debugEnabled = true;/*from w  ww. j  av  a2s .c  o  m*/
    } else {
        debugEnabled = false;
    }
    try {

        if (debugEnabled) {
            watch = new StopWatch();
            watch.start();
            logger.debug(MemoryUtils.getMemoryInfo().toString());
        }

        beforeHandle(request);

        ModelAndView modelAndView = super.handle(request, response, handler);

        if (modelAndView != null) {

            afterHandle(request, modelAndView);

            return modelAndView;

        }
    } finally {

        if (debugEnabled) {
            watch.stop();
            logger.debug("Request executed in " + watch.getTotalTimeMillis() + " milliseconds");
        }
    }

    return null;
}

From source file:org.bpmscript.correlation.CorrelationSupportTest.java

public void testHashPerformance() throws Exception {
    CorrelationSupport correlationSupport = new CorrelationSupport();
    StopWatch md5Watch = new StopWatch();

    Object[] values = new Object[3];
    values[0] = 100000;/*from   w  w w  .  ja  v a  2s  .c  o  m*/
    values[1] = "test ";
    values[2] = "randomblahblah";
    byte[] bytes = correlationSupport.getBytes(values);

    md5Watch.start();

    for (int i = 0; i < 100000; i++) {
        getHashMD5(bytes);
    }

    md5Watch.stop();

    System.out.println(md5Watch.getTotalTimeMillis());

    StopWatch hashCodeWatch = new StopWatch();

    hashCodeWatch.start();

    for (int i = 0; i < 100000; i++) {
        getHashHashCode(bytes);
    }

    hashCodeWatch.stop();

    System.out.println(hashCodeWatch.getTotalTimeMillis());
}

From source file:org.dd4t.core.filters.impl.DefaultLinkResolverFilter.java

/**
 * Recursively resolves all components links.
 * //ww  w  .ja  va 2 s  .  c om
 * @param item the to resolve the links
 * @param context the requestContext
 */
@Override
public void doFilter(Item item, RequestContext context) throws FilterException {

    this.getLinkResolver().setContextPath(contextPath);

    StopWatch stopWatch = null;
    if (logger.isDebugEnabled()) {
        stopWatch = new StopWatch();
        stopWatch.start();
    }
    if (item instanceof GenericPage) {
        resolvePage((GenericPage) item);
    } else if (item instanceof GenericComponent) {
        resolveComponent((GenericComponent) item);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "DefaultLinkResolverFilter. Item is not a GenericPage or GenericComponent so no component to resolve");
        }
    }
    if (logger.isDebugEnabled()) {
        stopWatch.stop();
        logger.debug("LinkResolverFilter for " + item.getId() + " finished in " + stopWatch.getTotalTimeMillis()
                + " ms");
    }
}