[
https://issues.apache.org/jira/browse/STATISTICS-75?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17772561#comment-17772561
]
Alex Herbert commented on STATISTICS-75:
----------------------------------------
I created a simple benchmark to initialise a statistic from an input array. The
statistic was a simple sum of values. Data were random values in [0, 1).
Methods tested:
{code:java}
double[] data = ...
DoubleConsumer s = ...
// forLoop
for (int i = 0; i < data.length; i++) {
s.accept(data[i]);
}
// forEachLoop
for (final double x : data) {
s.accept(x);
}
// streamForEach
Arrays.stream(data).forEach(s::accept);
{code}
Results (Java version: 11.0.20.1):
|length|forEachLoop|forLoop|streamForEach|
|0|2.44|2.46|16.37|
|1|4.17|4.18|17.12|
|10|8.00|7.83|21.51|
|100|59.42|59.80|89.67|
|1000|790.26|790.36|814.05|
|10000|8056.13|8102.35|8112.76|
h2. Conclusion
Creation of a stream is not as fast on small input arrays. On arrays above size
1000 the difference is negligible.
> Create JMH benchmarks for statistic initialization
> --------------------------------------------------
>
> Key: STATISTICS-75
> URL: https://issues.apache.org/jira/browse/STATISTICS-75
> Project: Commons Statistics
> Issue Type: Sub-task
> Components: descriptive
> Reporter: Anirudh Joshi
> Priority: Minor
> Labels: gsoc, gsoc2023
>
> Create JMH benchmarks for statistic initialization comparing Arrays.stream to
> a simple for loop.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)