Created
May 5, 2016 19:23
-
-
Save LiSongMWO/36b6964df802491e792aab3edf70154f to your computer and use it in GitHub Desktop.
Performance benchmark Java LinkedList vs ArrayList appending.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package perf; | |
import java.util.ArrayList; | |
import java.util.LinkedList; | |
import net.tuis.ubench.UBench; | |
public class Lists { | |
public static void main(String[] args) throws Exception { | |
final UBench bench = new UBench("ArrayList VS LinkedList"); | |
for (int n = 100; n < 100000; n *= 10) { | |
final int N = n; | |
bench.addTask("ArrayList " + N, () -> { | |
ArrayList<Integer> ans = new ArrayList<>(); | |
for (int x = 0; x < N; ++x) | |
ans.add(x); | |
return null; | |
}); | |
bench.addTask("LinkedList " + N, () -> { | |
LinkedList<Integer> ans = new LinkedList<>(); | |
for (int x = 0; x < N; ++x) | |
ans.add(x); | |
return null; | |
}); | |
} | |
bench.press(100).report("Comparison ArrayList vs LinkedList"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results for N=10^6:
Task ArrayList VS LinkedList -> ArrayList 1000000: (Unit: MICROSECONDS)
Count : 100 Average : 8694,9910
Fastest : 5773,0200 Slowest : 172363,0130
95Pctile : 11564,3580 99Pctile : 172363,0130
TimeBlock : 24397,939 7654,109 6032,919 9987,340 5982,441 5993,191 8286,964 6020,457 6438,276 6156,277
Histogram : 94 5 0 0 1
Task ArrayList VS LinkedList -> LinkedList 1000000: (Unit: MICROSECONDS)
Count : 100 Average : 11676,7730
Fastest : 4849,9380 Slowest : 116309,6150
95Pctile : 81683,8060 99Pctile : 116309,6150
TimeBlock : 26185,849 23320,629 7624,831 10119,136 5167,101 13491,721 7648,704 5177,881 12892,858 5139,024
Histogram : 79 14 1 1 5