🐢Performance Tests

Since 1.0.0

MCUtils offers a quick and easy way to run performance tests that offer minimum, average and maximum execution time results per task. Note that this tests may not be 100% precise and real performance will vary depending on a lot of factors such as server load. This is just for fast tests. Let's assume we want to test the performance of MCStrings#applyColor(String):

Runnable task = () -> MCStrings.applyColor("&4&l&oMCUtils")
new PerformanceTest(500000, 100)
    .addTest("applyColor", task)
    .run(System.out, 10);

Alright, here are a few things to note, but first, let's explain what every value means here.

  • task: This is the Runnable that will be executed by the performance test as a task.

  • 500000: The amount of times to call every task per test, as applying colors on a string is pretty fast, we need to call it a lot of times to notice performance differences.

  • 100: This is the time (in milliseconds) that the performance test thread will sleep per task, used to ensure that the CPU has recovered from the last task execution.

  • "applyColor": This is the ID of the task, will be used to display the data later on.

  • System.out: The stream to print the data, normally, System.out, but you can choose another one.

  • 10: The times to repeat this performance test, used to get an average statistic of the results, normally, you want more than 10 test to have more accurate results.

So, with all of that in mind, this test will run task 500000 times per test, sleeping 100 milliseconds at the end of every test, repeating this 10 times and printing the results on System.out. And yes, you can add as many tasks as you want before calling the run method, they will be added to the results and you can use that to compare different methods.

Last updated