Package org.springframework.util

Examples of org.springframework.util.StopWatch


    int leftCount = 2;
    Map beans = new HashMap();
    beans.put("status1",status);
    beans.put("leftCount", leftCount);
    Boolean result = true;
    /**!
     * 首先是apache的exp,看看效率如何
     */
    final StopWatch clock = new StopWatch("Performance");
    clock.start("jexl2");
    for(int i=0;i<count;i++){
      Configuration conf = new Configuration();
      ExpressionParser exprParser = new ExpressionParser( test, beans, conf );
          Expression testExpr = exprParser.parse();
          try {
              result = (Boolean) testExpr.evaluate();
          } catch (Exception e) {
            e.printStackTrace();
          }
    }
    clock.stop();
//        System.out.println(clock.prettyPrint());
        /**!
         * 其次是MVEL,看看效率如何
         */
        clock.start("MVEL");
        for(int i=0;i<count;i++){
          result = (Boolean)ScriptEvaluator.evalWithMVEL(test.substring(2, test.length()-1),beans);
        }
        clock.stop();
        System.out.println(clock.prettyPrint());
       
  }
View Full Code Here


   * @see #setExitMessage
   * @see #setExceptionMessage
   */
  protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
    String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName();
    StopWatch stopWatch = new StopWatch(name);
    Object returnValue = null;
    boolean exitThroughException = false;
    try {
      stopWatch.start(name);
      writeToLog(logger,
          replacePlaceholders(this.enterMessage, invocation, null, null, -1));
      returnValue = invocation.proceed();
      return returnValue;
    }
    catch (Throwable ex) {
      if(stopWatch.isRunning()) {
        stopWatch.stop();
      }
      exitThroughException = true;
      writeToLog(logger,
          replacePlaceholders(this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
      throw ex;
    }
    finally {
      if (!exitThroughException) {
        if(stopWatch.isRunning()) {
          stopWatch.stop();
        }
        writeToLog(logger,
            replacePlaceholders(this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
      }
    }
  }
View Full Code Here

public class MethodDecorator implements MethodInterceptor{
  private static final Logger LOG = LoggerFactory
  .getLogger(MethodDecorator.class);
  @Override
  public Object invoke(final MethodInvocation arg0) throws Throwable {
       final StopWatch clock = new StopWatch(
               "Profiling for '" + arg0.getClass().getName() + "' and '" + arg0.getArguments() + "'");
         try {
            clock.start(arg0.getMethod().getName());
            return arg0.proceed();
         } finally {
            clock.stop();
            LOG.info(clock.prettyPrint());
         }   
  }
View Full Code Here

    public void setOrder(final int order) {
        this.order = order;
    }
   
  public Object profile(final ProceedingJoinPoint call) throws Throwable {
        final StopWatch clock = new StopWatch(call.toLongString());
        String argValue = null;
        try {
           clock.start(call.toShortString());
           return call.proceed();
        } finally {
           clock.stop();
           StringBuffer sb = new StringBuffer();
           sb.append("\n");
           sb.append(clock.prettyPrint());
          
           Object[] args = call.getArgs();
           if(args!=null&&args.length>0){
             sb.append("With ");
             sb.append(args.length);
View Full Code Here

   * @see #setExitMessage
   * @see #setExceptionMessage
   */
  protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
    String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName();
    StopWatch stopWatch = new StopWatch(name);
    Object returnValue = null;
    boolean exitThroughException = false;
    try {
      stopWatch.start(name);
      writeToLog(logger,
          replacePlaceholders(this.enterMessage, invocation, null, null, -1));
      returnValue = invocation.proceed();
      return returnValue;
    }
    catch (Throwable ex) {
      if(stopWatch.isRunning()) {
        stopWatch.stop();
      }
      exitThroughException = true;
      writeToLog(logger,
          replacePlaceholders(this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
      throw ex;
    }
    finally {
      if (!exitThroughException) {
        if(stopWatch.isRunning()) {
          stopWatch.stop();
        }
        writeToLog(logger,
            replacePlaceholders(this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
      }
    }
  }
View Full Code Here

    assertEquals("", ServletRequestUtils.getRequiredStringParameter(request, "paramEmpty"));
  }

  public void testGetIntParameterWithDefaultValueHandlingIsFastEnough() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    StopWatch sw = new StopWatch();
    sw.start();
    for (int i = 0; i < 1000000; i++) {
      ServletRequestUtils.getIntParameter(request, "nonExistingParam", 0);
    }
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }
View Full Code Here

    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }

  public void testGetLongParameterWithDefaultValueHandlingIsFastEnough() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    StopWatch sw = new StopWatch();
    sw.start();
    for (int i = 0; i < 1000000; i++) {
      ServletRequestUtils.getLongParameter(request, "nonExistingParam", 0);
    }
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }
View Full Code Here

    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }

  public void testGetFloatParameterWithDefaultValueHandlingIsFastEnough() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    StopWatch sw = new StopWatch();
    sw.start();
    for (int i = 0; i < 1000000; i++) {
      ServletRequestUtils.getFloatParameter(request, "nonExistingParam", 0f);
    }
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }
View Full Code Here

    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }

  public void testGetDoubleParameterWithDefaultValueHandlingIsFastEnough() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    StopWatch sw = new StopWatch();
    sw.start();
    for (int i = 0; i < 1000000; i++) {
      ServletRequestUtils.getDoubleParameter(request, "nonExistingParam", 0d);
    }
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }
View Full Code Here

    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }

  public void testGetBooleanParameterWithDefaultValueHandlingIsFastEnough() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    StopWatch sw = new StopWatch();
    sw.start();
    for (int i = 0; i < 1000000; i++) {
      ServletRequestUtils.getBooleanParameter(request, "nonExistingParam", false);
    }
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
  }
View Full Code Here

TOP

Related Classes of org.springframework.util.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.