[英]How to compute the 90% distribution value from a set of number in java or linux command line?
I ran my integration test and got a list of execution time back. 我运行了集成测试,并获得了执行时间的列表。 I need to find the 90% distribution value from that set of result not the average.
我需要从该组结果中找到90%的分配值,而不是平均值。 Because it represents what the user will encounter 90% of the time.
因为它代表用户90%的时间会遇到的情况。 Is there a linux command line that does that?
有Linux命令行可以做到这一点吗? If not is there a java library that does that?
如果没有,那么有一个Java库吗?
Thanks, 谢谢,
Sean 肖恩
Assuming you have a file with each measurement on a separate line, with the actual measurement in the first column, count the lines, call that number L; 假设您有一个文件,每个度量值都位于单独的行中,而实际度量值在第一列中,则对行进行计数,将数字称为L; sort reversed, print the first field from the L/10th line.
反向排序,从第L / 10行打印第一个字段。 How you round a non-integer L/10 is up to you;
如何舍入非整数L / 10取决于您; you could also interpolate a value between n(floor(L/10)) and n(ceil(L/10)).
您还可以在n(floor(L / 10))和n(ceil(L / 10))之间插入一个值。
#!/bin/sh
L=$(wc -l <data.txt)
sort -r -n data.txt |
awk "NR >= $L/10"'{print $1; exit}'
This assumes fields are whitespace-separated. 这假设字段是用空格分隔的。
You are looking for a 90th percentile . 您正在寻找第90个百分位 。 Simply sort the execution times from shortest to longest and pick the one lying 10% from the end.
只需将执行时间从最短到最长排序,然后从末尾选择10%即可。 The quoted article explains other methods.
引用的文章解释了其他方法。
You can easily implement this using Java or Unix commands: sort
, wc
, head
and tail
or sed
. 您可以使用Java或Unix命令轻松地实现此目的:
sort
, wc
, head
和tail
或sed
。
If you store your times in a List or an array you can do this. 如果您将时间存储在列表或数组中,则可以执行此操作。
If not is there a java library that does that?
如果没有,那么有一个Java库吗?
Its just a couple of lines of Java code. 它只是几行Java代码。 I would just add it to your Java program so you have less output to deal with.
我只是将其添加到您的Java程序中,所以您需要处理的输出更少。
List<Long> times = new ArrayList<>();
// add times
Collections.sort(times);
System.out.printf("The typical, 90%% and 99%%tile times were %,d / %,d / %,d %n",
times.get(times.size()/2), times.get(times.size()*9/10), times.get(times.size()*99/100));
or 要么
long[] times = new long[SAMPLES];
// add times and
Arrays.sort(times);
System.out.printf("The typical, 90%% and 99%%tile times were %,d / %,d / %,d %n",
times[SAMPLES/2], times[SAMPLES*9/10], times[SAMPLES*99/100]);
Because it represents what the user will encounter 90% of the time.
因为它代表用户90%的时间会遇到的情况。
Actually the 90th percentile is the time its will less than 90% of the time. 实际上,第90个百分位是它不到90%的时间的时间。 The user will only experience this delay (or more) 10% of the time.
用户将仅在10%的时间内遇到此延迟(或更多)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.