From f880b1f60dcfb278ab00e6b20994072b04dfd5af Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 6 Nov 2012 19:02:53 +0100 Subject: [PATCH 1/1] genzip updates Signed-off-by: Jens Axboe --- t/genzipf.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/t/genzipf.c b/t/genzipf.c index adf914e2..f2867442 100644 --- a/t/genzipf.c +++ b/t/genzipf.c @@ -8,6 +8,9 @@ * * t/genzipf zipf 1.2 100000 20 * + * Only the distribution type (zipf or pareto) and spread input need + * to be given, if not given defaults are used. + * */ #include #include @@ -16,6 +19,9 @@ #include "../lib/zipf.h" +#define DEF_NR 1000000 +#define DEF_NR_OUTPUT 23 + static int val_cmp(const void *p1, const void *p2) { const unsigned long *v1 = p1; @@ -29,12 +35,12 @@ int main(int argc, char *argv[]) unsigned long nranges, output_nranges; unsigned long *vals; unsigned long i, j, nr_vals, cur_vals, max_val, interval; - double *output; + double *output, perc, perc_i; struct zipf_state zs; int use_zipf; double val; - if (argc < 4) { + if (argc < 3) { printf("%s: {zipf,pareto} val values [output ranges]\n", argv[0]); return 1; } @@ -49,14 +55,16 @@ int main(int argc, char *argv[]) } val = atof(argv[2]); - nranges = strtoul(argv[3], NULL, 10); - if (argc == 5) + + nranges = DEF_NR; + output_nranges = DEF_NR_OUTPUT; + + if (argc >= 4) + nranges = strtoul(argv[3], NULL, 10); + if (argc >= 5) output_nranges = strtoul(argv[4], NULL, 10); - else - output_nranges = nranges; - printf("Generating %s distribution with %f input and %lu ranges\n", use_zipf ? "zipf" : "pareto", val, nranges); - getchar(); + printf("Generating %s distribution with %f input and %lu ranges.\n", use_zipf ? "zipf" : "pareto", val, nranges); if (use_zipf) zipf_init(&zs, nranges, val); @@ -101,8 +109,12 @@ int main(int argc, char *argv[]) j++; } - for (i = 0; i < j; i++) - printf("%.2f%%\n", output[i]); + perc_i = 100.0 / (double) output_nranges; + perc = 0.0; + for (i = 0; i < j; i++) { + printf("%6.2f%% -> %6.2f%%:\t%6.2f%%\n", perc, perc + perc_i, output[i]); + perc += perc_i; + } free(output); free(vals); -- 2.25.1