Vadim Tkachenko has proposed merging lp:~vadim-tk/sysbench/sysbench-pareto into
lp:sysbench.
Requested reviews:
Alexey Kopytov (akopytov)
For more details, see:
https://code.launchpad.net/~vadim-tk/sysbench/sysbench-pareto/+merge/80975
This is probably not good enough quality code, but to give
an idea how to implement pareto function
--
https://code.launchpad.net/~vadim-tk/sysbench/sysbench-pareto/+merge/80975
Your team sysbench-developers is subscribed to branch lp:sysbench.
=== modified file 'sysbench/sysbench.c'
--- sysbench/sysbench.c 2011-09-26 13:54:56 +0000
+++ sysbench/sysbench.c 2011-11-02 02:50:28 +0000
@@ -63,6 +63,8 @@
# include <limits.h>
#endif
+#include <math.h>
+
#include "sysbench.h"
#include "sb_options.h"
#include "scripting/sb_script.h"
@@ -78,6 +80,7 @@
{
DIST_TYPE_UNIFORM,
DIST_TYPE_GAUSSIAN,
+ DIST_TYPE_PARETO,
DIST_TYPE_SPECIAL
} rand_dist_t;
@@ -124,7 +127,7 @@
{"help", "print help and exit", SB_ARG_TYPE_FLAG, NULL},
{"version", "print version and exit", SB_ARG_TYPE_FLAG, "off"},
{"rand-init", "initialize random number generator", SB_ARG_TYPE_FLAG, "off"},
- {"rand-type", "random numbers distribution {uniform,gaussian,special}", SB_ARG_TYPE_STRING,
+ {"rand-type", "random numbers distribution {uniform,gaussian,special,pareto}", SB_ARG_TYPE_STRING,
"special"},
{"rand-spec-iter", "number of iterations used for numbers generation", SB_ARG_TYPE_INT, "12"},
{"rand-spec-pct", "percentage of values to be treated as 'special' (for special distribution)",
@@ -898,6 +901,11 @@
rand_type = DIST_TYPE_GAUSSIAN;
rand_func = &sb_rand_gaussian;
}
+ else if (!strcmp(s, "pareto"))
+ {
+ rand_type = DIST_TYPE_PARETO;
+ rand_func = &sb_rand_pareto;
+ }
else if (!strcmp(s, "special"))
{
rand_type = DIST_TYPE_SPECIAL;
@@ -1096,6 +1104,15 @@
return a + sb_rnd() % (b - a + 1);
}
+/* pareto distribution */
+
+int sb_rand_pareto(int a, int b)
+{
+ double rangen;
+ rangen = drand48();
+ return round( pow( (pow(a, 1.161) / (rangen*pow((double)((double)a/(double)b), 1.161) - rangen + 1)), (1/1.161)));
+}
+
/* gaussian distribution */
int sb_rand_gaussian(int a, int b)
=== modified file 'sysbench/sysbench.h'
--- sysbench/sysbench.h 2011-07-21 17:02:14 +0000
+++ sysbench/sysbench.h 2011-11-02 02:50:28 +0000
@@ -221,6 +221,7 @@
/* Random number generators */
int sb_rand(int, int);
int sb_rand_uniform(int, int);
+int sb_rand_pareto(int, int);
int sb_rand_gaussian(int, int);
int sb_rand_special(int, int);
int sb_rand_uniq(int a, int b);
_______________________________________________
Mailing list: https://launchpad.net/~sysbench-developers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~sysbench-developers
More help : https://help.launchpad.net/ListHelp