[英]How to improve performance (paralellization or other ideas) calculation of multiple stats of array max, min, mean and std dev?
this is a continuation of this post<\/a> .这是这篇文章<\/a>的延续。 I must calculate many times some statistics(Max, mean, min, median and std dev) of arrays and I have a performance issue given the sort of my arrays in the method calcMaxMinMedian.我必须多次计算数组的一些统计数据(最大值、平均值、最小值、中值和标准偏差),并且在方法 calcMaxMinMedian 中给定我的数组类型时,我遇到了性能问题。
I have seen this doc<\/a> but I am not familiar As well as this (post)[https:\/\/stackoverflow.com\/questions\/20375176\/should-i-always-use-a-parallel-stream-when-possible\/20375622].我看过这个文档<\/a>,但我不熟悉以及这个(帖子)[https:\/\/stackoverflow.com\/questions\/20375176\/should-i-always-use-a-parallel-stream-when-possible\/20375622] .
Time (s) functionUsingForLoop173
Time (s) functionUsingParallelStream194
Part of your issue is that you are computing your randomised the data samples inside the tests, but have contention with the singleton random number generation in parallel threads.您的部分问题是您正在计算测试中的随机数据样本,但与并行线程中的单例随机数生成存在争用。 Also this means that you have no means of validating that the parallel algorithm matches the serial results.这也意味着您无法验证并行算法是否与串行结果匹配。
Refactor your tests so that inputs are pre-computed once - you don't care about timing this step:重构您的测试,以便预先计算一次输入 - 您不关心此步骤的时间安排:
private double[][] generateInputData(int numVals, int numCalculations) {
// calculations that is used to get some values, but is not modified.
double[][] inputs = new double[numCalculations][];// Each
for (int i = 0; i < numCalculations; i++) {
inputs[i] = functionSimulateCalculations(numVals);
}
return inputs;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.