开发者

Profile java parallel/sequential sorting

开发者 https://www.devze.com 2023-01-28 06:54 出处:网络
Does anyone know good way to profile a sorting algorithm in java(sequential and fork join) ? because the running time is too short (sorting list size 5000..), System.nanoTime() se开发者_Python百科ems

Does anyone know good way to profile a sorting algorithm in java(sequential and fork join) ? because the running time is too short (sorting list size 5000..), System.nanoTime() se开发者_Python百科ems not work properly.

I plan to run same test case many times (1000) and get rid of first 100 results (avoid HotSpot compiler problem) and do an average of running time using System.nanoTime(). Any suggestion on this ?

Thanks a lot!

Can I do this way ?

double count = 0;
double start, end;
for(int r = 0; r < warmup; r++) {
    // do test
}
for(int t = 0; t < runs; t++){
    start = System.nanoTime();
    // do test
    end = System.nanoTime();
    count += start - end;
}
double avg = count/avg


If the real-world running time is too short to benchmark, it's probably not worthwhile to optimize it.

If you're only sorting lists of 5000 elements, it's probably best to go with the simplest solution rather than prematurely optimizing it. If your lists are significantly larger, then you should be benchmarking on those large lists instead of smaller ones.


I can assure you that nanoTime() does work and if you want to avoid all hotspot warmup you need to run it 10K times. You should find that a sort of 5K element is fairly quick and even 1K test is not very much. You need to write a test which produces reproduce-able results. If you haven't, that is down to you to fix the test because it not very good.

I suggest you try it and see what results you get.

On an old computer, a sort of 5K random int values takes about 500 us. Note: sorting a sorted array will not give you same result. (so you cannot sort the same array each time)

A simple way to run a test a certain number of times ignoring the first N runs is to do.

long start = 0;
for(int r = -warmup; r < runs; r++) {
    if (r == 0) start = System.nanoTime();
    // do test
}
long avg = (System.nanoTime() - start)/runs;


Start by sorting a larger list. I'd say 50,000,000 elements is more reasonable if you're trying to compare benchmark times.

0

精彩评论

暂无评论...
验证码 换一张
取 消