2 * Generate/analyze pareto/zipf distributions to better understand
3 * what an access pattern would look like.
5 * For instance, the following would generate a zipf distribution
6 * with theta 1.2, using 100,000 values and split the reporting into
9 * t/genzipf zipf 1.2 100000 20
11 * Only the distribution type (zipf or pareto) and spread input need
12 * to be given, if not given defaults are used.
20 #include "../lib/zipf.h"
22 #define DEF_NR 1000000
23 #define DEF_NR_OUTPUT 23
25 static int val_cmp(const void *p1, const void *p2)
27 const unsigned long *v1 = p1;
28 const unsigned long *v2 = p2;
33 int main(int argc, char *argv[])
35 unsigned long nranges, output_nranges;
37 unsigned long i, j, nr_vals, cur_vals, max_val, interval;
38 double *output, perc, perc_i;
44 printf("%s: {zipf,pareto} val values [output ranges]\n", argv[0]);
48 if (!strcmp(argv[1], "zipf"))
50 else if (!strcmp(argv[1], "pareto"))
53 printf("Bad distribution type <%s>\n", argv[1]);
60 output_nranges = DEF_NR_OUTPUT;
63 nranges = strtoul(argv[3], NULL, 10);
65 output_nranges = strtoul(argv[4], NULL, 10);
67 printf("Generating %s distribution with %f input and %lu ranges.\n", use_zipf ? "zipf" : "pareto", val, nranges);
70 zipf_init(&zs, nranges, val);
72 pareto_init(&zs, nranges, val);
74 vals = malloc(nranges * sizeof(unsigned long));
76 max_val = nr_vals = 0;
77 for (i = 0; i < nranges; i++) {
79 vals[nr_vals] = zipf_next(&zs);
81 vals[nr_vals] = pareto_next(&zs);
83 if (vals[nr_vals] > max_val)
84 max_val = vals[nr_vals];
88 qsort(vals, nr_vals, sizeof(unsigned long), val_cmp);
90 interval = (max_val + output_nranges - 1) / output_nranges;
92 output = malloc(output_nranges * sizeof(double));
94 for (i = j = 0, cur_vals = 0; i < nr_vals; i++) {
95 if (vals[i] > interval) {
96 output[j] = (double) (cur_vals + 1) / (double) nr_vals;
100 interval += (max_val + output_nranges - 1) / output_nranges;
107 output[j] = (double) (cur_vals + 1) / (double) nr_vals;
112 perc_i = 100.0 / (double) output_nranges;
114 for (i = 0; i < j; i++) {
115 printf("%6.2f%% -> %6.2f%%:\t%6.2f%%\n", perc, perc + perc_i, output[i]);