淘宝商城(天猫)高级技术专家.3年研发+3年性能测试调优/系统测试+4年团队管理与测试架构、研发系统实践. 新舞台新气象, 深化测试基础架构及研发架构,希望能在某个技术领域成为真正的技术大牛。欢迎荐才http://bbs.51testing.com/viewthread.php?tid=120496&extra=&page=1 .邮件: jianzhao.liangjz@alibaba-inc.com,MSN:liangjianzhao@163.com.微博:http://t.sina.com.cn/1674816524

P-unit0.15 应用

上一篇 / 下一篇  2009-01-02 13:22:43 / 个人分类:java性能监控与调优

 

 

参考:http://zhanghuangzhu.blogspot.com/search/label/p-unit

http://blog.csdn.net/zhanghuangzhu/

 

https://sourceforge.net/projects/p-unit下载.

Samples文件编译runner.runVMs失败,不再支持runVMs.

加入libsjar以及p-unit-0.15.319.jar, p-unit-0.15.319-extension.jar

从执行结果看,p-unitjunitperf是不同的。P-unit有内存消耗图片。

Junitperf并发执行控制粒度控制更加细致。

 

ParamTestClass.java内容:

 

packagesamples;

importorg.punit.reporter.chart.OverviewReporter;

importorg.punit.reporter.chart.image.ImageRender;

importorg.punit.reporter.chart.pdf.PDFRender;

importorg.punit.reporter.stream.file.FileLogger;

importorg.punit.runner.*;

importorg.punit.type.*;

importorg.punit.watcher.MemoryWatcher;

 

publicclassParamTestClassimplementsParameterized {

 

   publicstaticvoidmain(String[] args) {

      ConcurrentRunner runner =newConcurrentRunner();

      //加入内存消耗监控

      runner.methodRunner().addWatcher(newMemoryWatcher());

 

      runner.addEventListener(newFileLogger());

      runner.addEventListener(newOverviewReporter(newImageRender()));

      runner.addEventListener(newOverviewReporter(newPDFRender()));

      //利用多核特性

      runner.setExecutorPool(newExecutorPoolImpl(2));

 

      runner.run(ParamTestClass.class);

   }

 

   publicParameter[] parameters() {

      returnnewParameter[] {newParameterImpl(2),newParameterImpl(10),

             newParameterImpl(30) };

   }

 

   publicvoidtestA(ParameterImpl param) {

      System.out.println("testA count = "+ param.count());//$NON-NLS-1$

      SampleUtil.doSomething(param.count());

   }

 

   

   publicvoidsetUpAfterWatchers(Parameter param)throwsException {

 

   }

 

   publicvoidsetUpBeforeWatchers(Parameter param)throwsException {

 

   }

 

   publicvoidtearDownAfterWatchers(Parameter param)throwsException {

 

   }

 

   publicvoidtearDownBeforeWatchers(Parameter param)throwsException {

 

   }

 

   staticclassParameterImplimplementsParameter {

      privateint_count;

 

      ParameterImpl(intcount) {

          _count= count;

      }

 

      publicintcount() {

          return_count;

      }

 

      publicString toString() {

          returnString.valueOf(_count);

      }

   }

}

 

 

SampleUtil.java内容

packagesamples;

 

import java.util.*;

 

import org.punit.util.*;

 

public class SampleUtil {

             

      private static Random _random = new Random();

      

      public static void consumeMemory(int length) {

             byte[] data = new byte[length];

             for(int i = 0, j = 0; i < data.length; ++i) {

                    ++j;

             }

      }

      

      public static void consumeTime(int time) {

             ThreadUtil.sleepIgnoreInterruption(time);

      }

      

      public static void doSomething() {

             consumeTime(Math.abs(_random.nextInt()) % 500);

             consumeMemory(Math.abs(_random.nextInt()) % 100000);

      }

      public static void doSomething(int count) {

             for(int i=0;i<count;i++)

             {

             consumeTime(Math.abs(_random.nextInt()) % 500);

             consumeMemory(Math.abs(_random.nextInt()) % 100000);

             }

      }

      

}

 

控制台执行时间,与内存消耗值。

testA(30) - [9741.979497ms,504864.0bytes]

total: 3, failures:0 (GREEN) - 16922.606365ms

 

执行目录下result下生成pdf,txt,png格式的文件结果

 


TAG: p-unit junitperf 单元级性能测试 java性能监控与调优

 

评分:0

我来说两句

Open Toolbar