简体   繁体   English

"如何提高数组 max、min、mean 和 std dev 的多个统计数据的性能(并行化或其他想法)计算?"

[英]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 中给定我的数组类型时,我遇到了性能问题。

Given, I could not improve much further the summary statistics of an array performance.鉴于此,我无法进一步改进阵列性能的汇总统计数据。 I am trying now to understand strategies and work arounds to parallelize my upper calls or any other smart thoughts.我现在正在尝试理解策略和变通方法,以并行化我的上司或任何其他聪明的想法。

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] .

I tried using parallel streams, however probably given my SharedResource, the actual performance using the for loop was worse.我尝试使用并行流,但可能考虑到我的 SharedResource,使用 for 循环的实际性能更差。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM