Игорь Рыбаков Игорь Рыбаков - 1 year ago 142
Java Question

The fastest way to add elements in set collection

I have a task to add in treeset > 10000000 elements that are sequence.

If I use

for (long index = 0; index < 10000000; index++)

It takes 8083 ms. Is there any solution to increase the performance of this task?


P.S. The fastest way at the moment is:
List<Integer> range = IntStream.range(0, 10000000).boxed().collect(Collectors.toList());
with result of ~ 370 ms


Try HPPC: High Performance Primitive Collections for Java

License: Apache License 2.0


LongHashSet executes in 1190ms:

LongSet result = new LongHashSet();
for (Long index = 0L; index < 10000000L;) {

LongScatterSet executes in 850ms:

LongSet result = new LongScatterSet();
for (Long index = 0L; index < 10000000L;) {