Java Performance measurement

前端 未结 6 952
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 03:53

I am doing some Java performance comparison between my classes, and wondering if there is some sort of Java Performance Framework to make writing performance measurement cod

6条回答
  •  Happy的楠姐
    2020-12-10 04:05

    In short, you are thus searching for an "Java unit performance testing tool"?

    Use JUnitPerf.

    Update: for the case it's not clear yet: it also supports concurrent (multithreading) testing. Here's an extract of the chapter "LoadTest" of the aforementioned link which includes a code sample:

    For example, to create a load test of 10 concurrent users with each user running the ExampleTestCase.testOneSecondResponse() method for 20 iterations, and with a 1 second delay between the addition of users, use:

    int users = 10;
    int iterations = 20;
    Timer timer = new ConstantTimer(1000);
    Test testCase = new ExampleTestCase("testOneSecondResponse");
    Test repeatedTest = new RepeatedTest(testCase, iterations);
    Test loadTest = new LoadTest(repeatedTest, users, timer);
    

提交回复
热议问题