我有一套程序,对于每个程序,它包含许多子程序,其中一个子程序具有最长的运行时间。我的目标是计算(最长运行时间)/(整个程序运行时间)的平均比率。 我想知道这样做的正确方法是什么。
> program longest runtime entire runtime ratio
>
> 1 10 secs 50 secs 0.2
>
> 2 5 secs 40 secs 0.125
>
> 3 1 secs 10 secs 0.1
>
> 4 20 secs 80 secs 0.25
>
> 5 15 secs 20 secs 0.75
所以我想看看整个运行时最长运行时间的百分比。 有两种方法可以做到: 1:计算每个程序的比率,然后计算比率的平均值。
(0.2 + 0.125 + 0.1 + 0.25 + 0.75)/ 5 = 1.425 / 5 = 0.285
2:计算最长运行时间的总和,然后除以整个运行时间的总和。
sum_longest = 41秒
sum_entire = 200秒
平均值= 41/200 = 0.205
哪种方式正确?
答案 0 :(得分:1)
我说你的后一个答案(得到.205)是正确的,因为你的第一种方法不考虑权重(即每个程序运行多长时间)。