[v3,5/6] eal: add bounded PRNG performance tests

Message ID 20190605104400.24484-6-mattias.ronnblom@ericsson.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Pseudo-random number generation improvements |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Mattias Rönnblom June 5, 2019, 10:43 a.m. UTC
  Add best- and worst-case performance tests for rte_rand_max().

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/test_rand_perf.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
  

Patch

diff --git a/app/test/test_rand_perf.c b/app/test/test_rand_perf.c
index 771713757..fe797ebfa 100644
--- a/app/test/test_rand_perf.c
+++ b/app/test/test_rand_perf.c
@@ -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;
 }