Simperf :一個簡單的Java性能測試框架
Simperf 是一個簡單的性能測試工具,它提供了一個多線程測試框架
Example:
1. 在代碼里使用Simperf
Simperf perf = new Simperf(50, 2000, 1000, new SimperfThreadFactory() { public SimperfThread newThread() { return new SimperfThread(); } }); // 設置結果輸出文件,默認 simperf-result.log perf.getMonitorThread().setLogFile("simperf.log"); // 開始性能測試 perf.start();
2. 在命令行里使用Simperf
public class SimperfCommandTest { public static void main(String[] args) { SimperfCommand simCommand = new SimperfCommand(args); Simperf perf = simCommand.create(); if (perf == null) { // 參數解析失敗時會返回null System.exit(-1); } perf.start(new SimperfThreadFactory() { public SimperfThread newThread() { return new SimperfThread(); } }); } }
執行命令:
java SimperfCommandTest -t 10 -c 10 -i 1000 參數說明: usage: SimperfCommand options -c,--count [*] number of each thread requests count -i,--interval [ ] interval of print messages, default 1000 -j [ ] generate jtl report -l,--log [ ] log filename -m,--maxtps [ ] max tps -t,--thread [*] number of thread count
3. 在Junit4里使用Simperf
public class SimperfTestCaseTest extends SimperfTestCase { private Random rand; @Test @Simperf(thread = 2, count = 5, interval = 1000) public void testXxx() { try { Thread.sleep(1000); } catch (Exception e) { } boolean result = rand.nextInt(10) > 1; Assert.assertTrue("隨機生成結果", result); } }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!