// A Spliterator that counts the number of spliterators created // including itself, thus the count starts at 1 staticclass SplitCountingSpliterator<T> implements Spliterator<T> { final Spliterator<T> s; final AtomicInteger nsplits;
// Top-level constructor public SplitCountingSpliterator(Spliterator<T> s) { this.s = s;
nsplits = new AtomicInteger(1);
}
staticint countSplits(ForkJoinPool fjp) throws Exception { // The number of splits will be equivalent to the number of leaf nodes // and will be a power of 2 var fInteger = fjp.submit(() -> { var s = IntStream.range(0, 1024).boxed().parallel().spliterator(); var cs = new SplitCountingSpliterator<>(s);
StreamSupport.stream(cs, true).forEach(e -> {}); return cs.splits();
}); return fInteger.get();
}
staticint nearestPowerOfTwo(int i) { return (i & (i - 1)) == 0
? i
: 1 << (32 - Integer.numberOfLeadingZeros(i));
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.