eal: introduce random generator with upper bound
[dpdk.git] / app / test / test_rand_perf.c
index 7717137..fe797eb 100644 (file)
@@ -15,8 +15,13 @@ static volatile uint64_t vsum;
 
 #define ITERATIONS (100000000)
 
+#define BEST_CASE_BOUND (1<<16)
+#define WORST_CASE_BOUND (BEST_CASE_BOUND + 1)
+
 enum rand_type {
-       rand_type_64
+       rand_type_64,
+       rand_type_bounded_best_case,
+       rand_type_bounded_worst_case
 };
 
 static const char *
@@ -25,6 +30,10 @@ rand_type_desc(enum rand_type rand_type)
        switch (rand_type) {
        case rand_type_64:
                return "Full 64-bit [rte_rand()]";
+       case rand_type_bounded_best_case:
+               return "Bounded average best-case [rte_rand_max()]";
+       case rand_type_bounded_worst_case:
+               return "Bounded average worst-case [rte_rand_max()]";
        default:
                return NULL;
        }
@@ -46,6 +55,12 @@ test_rand_perf_type(enum rand_type rand_type)
                case rand_type_64:
                        sum += rte_rand();
                        break;
+               case rand_type_bounded_best_case:
+                       sum += rte_rand_max(BEST_CASE_BOUND);
+                       break;
+               case rand_type_bounded_worst_case:
+                       sum += rte_rand_max(WORST_CASE_BOUND);
+                       break;
                }
        }
 
@@ -68,6 +83,8 @@ test_rand_perf(void)
        printf("Pseudo-random number generation latencies:\n");
 
        test_rand_perf_type(rand_type_64);
+       test_rand_perf_type(rand_type_bounded_best_case);
+       test_rand_perf_type(rand_type_bounded_worst_case);
 
        return 0;
 }