]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
add benchmark
authorSvetlana <lana0771711@gmail.com>
Thu, 13 Aug 2020 15:17:36 +0000 (15:17 +0000)
committerSvetlana <lana0771711@gmail.com>
Thu, 13 Aug 2020 15:17:36 +0000 (15:17 +0000)
distbench/Makefile.am
distbench/bkjg.csv [new file with mode: 0644]
distbench/main.c
distbench/margalit.csv [new file with mode: 0644]
distbench/run-all.sh
distbench/sshmidt.csv [new file with mode: 0644]

index 8a4092140139a34de2173d9f895d6cc6461cb646..9944b211a0d0a0230203795286fb55199d190d29 100644 (file)
@@ -1,7 +1,11 @@
 bin_PROGRAMS = bkjg margalit sshmidt
 
 # If you need special libraries, e.g. libm (math lib), declare them like so:
-# xxx_LIBS = -lm
+bkjg_LDFLAGS = -lm
+
+margalit_LDFLAGS = -lm
+
+sshmidt_LDFLAGS = -lm
 
 bkjg_SOURCES = main.c function.h bkjg.c
 
diff --git a/distbench/bkjg.csv b/distbench/bkjg.csv
new file mode 100644 (file)
index 0000000..47b2a8f
--- /dev/null
@@ -0,0 +1,2 @@
+Number of buckets, Update linear, Percentile linear, Mixed linear, Update exponential, Percentile exponential, Mixed exponential, Update custom, Percentile custom, Mixed custom, Update all, Percentile all, Mixed all\n
+50, 0.802700, 1.862700, 1.229800, 4.674900, 2.202600, 4.890000, 0.807600, 1.911000, 1.230900, 2.628400, 0.597100, 2.926200 100, 0.814000, 2.096100, 1.239800, 8.080000, 2.327700, 1844674407280.051514, 0.829200, 2.099900, 1.382600, 4.579600, 0.514700, 3.890200 150, 0.820600, 2.414900, 1.309800, 11.700600, 2.174000, 11.175100, 0.849600, 2.354600, 1.302000, 4.989100, 0.513200, 4.935200 200, 0.843200, 2.420500, 1.293200, 15.177900, 2.397200, 1844674407286.233887, 1.158600, 2.341000, 1.332300, 6.212400, 0.518200, 6.108700 250, 0.864200, 2.335500, 1.318300, 18.639200, 2.480700, 17.402300, 0.982700, 2.426300, 1.373600, 7.348200, 0.518700, 7.087400 300, 0.883900, 1844674407274.555420, 1.402300, 22.566300, 2.301300, 20.700900, 0.976700, 2.599700, 1.463700, 8.578600, 0.512900, 8.187900 350, 0.971200, 2.583900, 1.381600, 1844674407297.518311, 2.439100, 23.864600, 1.035700, 2.642400, 1.529600, 9.754300, 0.519700, 9.246000 400, 0.956400, 2.625100, 1.425400, 29.161500, 2.501100, 1844674407299.223145, 1.152000, 2.641700, 1.561700, 11.022700, 0.515100, 13.581800 450, 1.056700, 2.702600, 1.529400, 32.963300, 1844674407274.551758, 30.617900, 1.205700, 2.658300, 1.667500, 12.162900, 0.518000, 11.466400 500, 1.055700, 2.627600, 1.510000, 1844674407308.593750, 2.536400, 33.539600, 1.295700, 2.631200, 1.729300, 13.378900, 0.518900, 12.693500 
\ No newline at end of file
index 4a433a91ec03df41dc88ef3c15ab89791932a573..2d429c0a849e2874aec5aa39ec51342e87e2f15e 100644 (file)
 #endif
 #include <unistd.h>
 
-/* Local headers */
-#include "function.h"
+#include "distribution.h"
+#include <stdio.h>
+#include <time.h>
+#include <math.h>
 
 /* Macro to exit with an error. */
 #define error(fmt, args...)                                                    \
@@ -21,7 +23,7 @@
   } while (0)
 
 /* How many nanoseconds there are in a second. */
-#define NANOS_PER_SECOND 10000000
+#define NANOS_PER_SEC 10000000
 
 /* How many microseconds there are in a nanosecond. */
 #define MICROS_PER_NANO 1000
@@ -44,29 +46,192 @@ static uint64_t get_clock() {
   if (gettimeofday(&tv, NULL) == -1)
     error("Unable to retrieve current time: %s", strerror(errno));
 
-  return (tv.tv_sec * NANOS_PER_SECOND) + (tv.tv_usec * MICROS_PER_NANO);
+  return (tv.tv_sec * NANOS_PER_SEC) + (tv.tv_usec * MICROS_PER_NANO);
 #endif
 }
 
+const size_t iterations = 1000000;
+const int dist_number = 3;
+
+static double * calculate_gauges_arr(double gauges[], size_t iterations) {
+    for(size_t i = 0; i < iterations; i++) {
+        gauges[i] = (double) (rand() % (int) 1e6);
+    }
+    return gauges;
+}
+
+static double * calculate_percents_arr(double percents[], size_t iterations) {
+    for(size_t i = 0; i < iterations; i++) {
+        percents[i] =  (double) (rand() % 101);
+    }
+    return percents;
+}
+
+static size_t * calculate_dist_index_arr(size_t indexes[], size_t iterations) {
+    for(size_t i = 0; i < iterations; i++) {
+        indexes[i] = rand() % 3;
+    }
+    return indexes;
+}
+
+double measure_update(distribution_t *dist, size_t iterations, double *gauges) {
+    uint64_t start = get_clock();
+    for(size_t i = 0; i < iterations; i++) {
+        distribution_update(dist, gauges[i]);
+    }
+    uint64_t end = get_clock();
+    double seconds = (end - start) / (double)(NANOS_PER_SEC);
+    printf("%f, ", seconds);
+    return seconds;
+}
+
+double measure_percentile(distribution_t *dist, size_t iterations, double *percents) {
+    uint64_t start = get_clock();
+    for(size_t i = 0; i < iterations; i++) {
+        volatile double res = distribution_percentile(dist, percents[i]);
+       (void)res;
+    }
+    uint64_t end = get_clock();
+    double seconds = (end - start) / (double)(NANOS_PER_SEC);
+    printf("%f, ", seconds);
+    return seconds;
+}
+
+double  measure_mixed(distribution_t *dist, size_t iterations, double *percents, double *gauges) {
+    uint64_t start = get_clock();
+    for(size_t i = 0; i < iterations; i++) {
+        if (i % 10 == 0) {
+         volatile double res = distribution_percentile(dist, percents[i]);
+         (void)res;
+       }
+        else {
+         distribution_update(dist, gauges[i]);
+       }
+    }
+    uint64_t end = get_clock();
+    double seconds = (end - start) / (double)(NANOS_PER_SEC);
+    printf("%f, ", seconds);
+    return seconds;
+}
+
+double measure_update_all_dists(distribution_t **dists, size_t iterations, double *gauges, size_t *indexes) {
+    uint64_t start = get_clock();
+    for(size_t i = 0; i < iterations; i++) {
+        distribution_update(dists[indexes[i]], gauges[i]);
+    }
+    uint64_t end = get_clock();
+    double seconds = (end - start) / (double)(NANOS_PER_SEC);
+    printf("%f, ", seconds);
+    return seconds;
+}
+
+double measure_percentile_all_dists(distribution_t **dists, size_t iterations, double *percents, size_t *indexes) {
+    uint64_t start = get_clock();
+    for(size_t i = 0; i < iterations; i++) {
+        volatile double res = distribution_percentile(dists[indexes[i]], percents[i]);
+       (void)res;
+    }
+    uint64_t end = get_clock();
+    double seconds = (end - start) / (double)(NANOS_PER_SEC);
+    printf("%f, ", seconds);
+    return seconds;
+}
+
+double measure_mixed_all_dists(distribution_t **dists, size_t iterations, double *percents, double *gauges, size_t *indexes) {
+    uint64_t start = get_clock();
+    for(size_t i = 0; i < iterations; i++) {
+        if (i % 10 == 0) {
+        volatile double res = distribution_percentile(dists[indexes[i]], percents[i]);
+        (void)res;
+        } 
+        else {
+         distribution_update(dists[indexes[i]], gauges[i]);
+       }
+    }
+    uint64_t end = get_clock();
+    double seconds = (end - start) / (double)(NANOS_PER_SEC);
+    printf("%f ", seconds);
+    return seconds;
+}
+
 int main(int argc, char **argv) {
-  uint64_t start = get_clock();
-
-  for (int i = 0; i < ITERATIONS; i++) {
-    /* Store result in a volatile to prevent the compiler from ignoring the call
-     * because the result is unused. */
-    volatile int result = my_function();
-
-    /* Prevent "unused variable" warning/error. */
-    (void)result;
-  }
-
-  uint64_t end = get_clock();
-  uint64_t duration = end - start;
-
-  printf("%s: %d iterations took %f seconds (~ %d nanoseconds per call)\n",
-         argv[0],    /* Program name */
-         ITERATIONS, /* Number of iterations */
-         (duration * 1.0 /
-          NANOS_PER_SECOND), /* *1.0 to force floating-point arithmetic */
-         (int)(duration / ITERATIONS)); /* Only integer division here */
+    srand(1770);
+    if (argc < 2) {
+        printf("No bucket number found.\n");
+        exit(EXIT_FAILURE);
+    }
+
+    int buckets_number = atoi(argv[1]);
+    double buckets_size = 25;
+
+    double *custom = malloc(sizeof(double) * buckets_number - 1);
+    if(custom == NULL) {
+        printf("Malloc failed.\n");
+        exit(EXIT_FAILURE);
+    } 
+
+    custom[0] = rand() % (100 + 1);
+    for (size_t i = 1; i < buckets_number - 1; i++) {
+        custom[i] = custom[i - 1] + rand() % 100 + 1;
+    }
+
+    distribution_t *dists[dist_number];
+    dists[0] = distribution_new_linear(buckets_number, buckets_size);
+    dists[1] = distribution_new_exponential(buckets_number, 3, 2);
+    dists[2] = distribution_new_custom(buckets_number - 1, custom);
+    free(custom);
+
+    double *gauges = malloc(sizeof(double) * iterations);
+    if(gauges == NULL) {
+        printf("Malloc failed.\n");
+        exit(EXIT_FAILURE);
+    } 
+    gauges = calculate_gauges_arr(gauges, iterations);
+
+    double *percents = malloc(sizeof(double) * iterations);
+    if(percents == NULL) {
+        printf("Malloc failed.\n");
+        exit(EXIT_FAILURE);
+    } 
+    percents = calculate_percents_arr(percents, iterations);
+
+    size_t *indexes = malloc(sizeof(size_t) * iterations);
+    if(indexes == NULL) {
+        printf("Malloc failed.\n");
+        exit(EXIT_FAILURE);
+    } 
+    indexes = calculate_dist_index_arr(indexes, iterations);
+    
+    /*printf("Number of buckets, 
+           Update linear, Percentile linear, Mixed linear, 
+           Update exponential, Percentile exponential, Mixed exponential, 
+           Update custom, Percentile custom, Mixed custom, 
+           Update all, Percentile all, Mixed all");*/
+
+    printf("%d, ", buckets_number);
+    volatile double res = measure_update(dists[0], iterations, gauges);
+    res = measure_percentile(dists[0], iterations, percents);
+    res = measure_mixed(dists[0], iterations, percents, gauges);
+
+    //printf("%d, ", buckets_number);
+    res = measure_update(dists[1], iterations, gauges);
+    res = measure_percentile(dists[1], iterations, percents);
+    res = measure_mixed(dists[1], iterations, percents, gauges);
+
+    //printf("%d, ", buckets_number);
+    res = measure_update(dists[2], iterations, gauges);
+    res = measure_percentile(dists[2], iterations, percents);
+    res = measure_mixed(dists[2], iterations, percents, gauges);
+
+    //printf("%d, ", buckets_number);
+    res = measure_update_all_dists(dists, iterations, gauges, indexes);
+    res = measure_percentile_all_dists(dists, iterations, gauges, indexes);
+    res = measure_mixed_all_dists(dists, iterations, percents, gauges, indexes);
+    (void)res;
+    free(gauges);
+    free(percents);
+    free(indexes);
+    for (size_t i = 0; i < dist_number; i++)
+       distribution_destroy(dists[i]);
+    return 0;
 }
diff --git a/distbench/margalit.csv b/distbench/margalit.csv
new file mode 100644 (file)
index 0000000..07abf1d
--- /dev/null
@@ -0,0 +1,2 @@
+Number of buckets, Update linear, Percentile linear, Mixed linear, Update exponential, Percentile exponential, Mixed exponential, Update custom, Percentile custom, Mixed custom, Update all, Percentile all, Mixed all\n
+50, 1.555600, 6.880600, 2.179300, 2.204800, 1844674407275.491211, 2.706900, 1.567000, 7.179300, 2.174500, 2.301500, 0.511900, 2.882300 100, 1.897600, 11.591900, 2.853400, 2.471400, 3.590200, 2.986700, 1.851200, 11.468100, 2.878100, 2.572500, 0.527200, 3.448600 150, 2.101800, 16.101300, 1844674407275.684814, 2.542500, 3.556400, 3.174800, 2.122200, 16.261700, 3.781500, 2.752400, 0.519500, 3.927300 200, 2.110800, 20.699300, 4.221200, 2.744400, 3.609100, 3.155600, 2.117200, 1844674407292.584229, 4.374800, 2.909700, 0.514800, 4.369600 250, 2.126700, 25.495600, 4.674000, 2.924500, 4.366700, 3.239600, 2.155600, 25.470100, 4.754300, 2.966600, 0.518600, 1844674407276.713135 300, 2.399400, 30.223800, 5.423700, 2.778000, 3.513500, 3.223300, 2.430600, 29.985700, 5.427200, 3.103000, 0.513200, 1844674407277.079346 350, 2.406100, 34.751700, 5.943700, 3.069200, 3.535700, 3.404900, 2.452000, 34.528300, 1844674407277.951416, 3.193300, 0.530400, 5.547600 400, 2.449700, 39.500900, 6.399200, 3.003300, 3.579200, 3.424500, 2.458200, 1844674407311.234619, 6.453000, 3.213000, 0.520500, 5.830100 450, 2.430600, 43.853300, 6.836700, 3.062200, 3.533300, 1844674407275.483398, 2.782900, 46.969000, 7.240500, 3.208600, 0.531200, 6.174700 500, 2.460300, 1844674407320.610107, 7.374100, 3.112600, 3.582700, 3.498400, 2.472500, 48.673900, 1844674407279.256348, 3.272900, 0.529000, 6.516300 
\ No newline at end of file
index 8de18fb9bf0d4569d5a168a0f14ea577bcc63837..24c507e215a1fbf2bbbd589a2c1c716606a8391a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # Change into distbench/ directory if not already.
 cd "$(dirname "$(readlink -f "$0")")"
@@ -7,8 +7,13 @@ cd "$(dirname "$(readlink -f "$0")")"
 make
 
 # Run all three benchmarks.
-for program in bkjg margalit sshmidt; do
-    echo "Running $program"
-    ./"$program"
-    echo
+for program in bkjg margalit sshmidt; 
+do
+    rm "$program".csv  
+    echo "Number of buckets, Update linear, Percentile linear, Mixed linear, Update exponential, Percentile exponential, Mixed exponential, Update custom, Percentile custom, Mixed custom, Update all, Percentile all, Mixed all\n"          >> "$program".csv          
+    for i in {50..500..50}
+    do
+        echo "Running $program for $i"
+        ./"$program" $i >> "$program".csv
+    done
 done
diff --git a/distbench/sshmidt.csv b/distbench/sshmidt.csv
new file mode 100644 (file)
index 0000000..6044348
--- /dev/null
@@ -0,0 +1,2 @@
+Number of buckets, Update linear, Percentile linear, Mixed linear, Update exponential, Percentile exponential, Mixed exponential, Update custom, Percentile custom, Mixed custom, Update all, Percentile all, Mixed all\n
+50, 1.455900, 2.049200, 1.836700, 2.069100, 3.007500, 2.403000, 1.462500, 1.996300, 1.841500, 2.213000, 0.550300, 2.468200 100, 1.654600, 2.192900, 2.025100, 2.174400, 3.127100, 2.528100, 1.677000, 2.188000, 2.039900, 2.413300, 0.539800, 2.678100 150, 1.872200, 2.377000, 2.210200, 2.259600, 3.023300, 2.570100, 1.851300, 2.338000, 2.200200, 2.523500, 0.539600, 1844674407274.784912 200, 2.303200, 2.771200, 2.213200, 2.324100, 3.151700, 2.687600, 1.890800, 2.402500, 2.229100, 2.490600, 0.548200, 2.827300 250, 1.862300, 2.347200, 2.205700, 2.458700, 3.284300, 2.783900, 1.948500, 2.513000, 2.200700, 2.633900, 0.553100, 2.846400 300, 2.104700, 2.552900, 2.431300, 2.436800, 3.104900, 2.721600, 2.064300, 2.511400, 2.406300, 2.696800, 0.548600, 2.998400 350, 2.068000, 3.098800, 2.403600, 2.475600, 3.052600, 2.722500, 2.054800, 2.569500, 2.454000, 2.721400, 0.553600, 2.985300 400, 2.062000, 2.535100, 2.454400, 2.536200, 3.166000, 2.851500, 2.090700, 2.536900, 2.445300, 2.738300, 0.566200, 3.024900 450, 2.134400, 2.633800, 2.443200, 2.668700, 3.398600, 2.943600, 2.089800, 2.556100, 2.429800, 2.738400, 0.541200, 1844674407275.146729 500, 2.540700, 2.513600, 2.432100, 2.648500, 3.433700, 2.961800, 2.130600, 2.620500, 2.475600, 2.715300, 0.536100, 3.071500 
\ No newline at end of file