From f0d6b88626223e2f8b77072fb628fdcf4a5f87ab Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Mon, 6 Mar 2017 14:20:26 -0800 Subject: Avoid repetitive division calculations --- test/core/support/cpu_test.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test/core/support') diff --git a/test/core/support/cpu_test.c b/test/core/support/cpu_test.c index ca0fe0ccb5..7b9bf6c5e1 100644 --- a/test/core/support/cpu_test.c +++ b/test/core/support/cpu_test.c @@ -81,9 +81,12 @@ static void worker_thread(void *arg) { uint32_t cpu; unsigned r = 12345678; unsigned i, j; - for (i = 0; i < 1000 / grpc_test_slowdown_factor(); i++) { + /* Avoid repetitive division calculations */ + int64_t max_i = 1000 / grpc_test_slowdown_factor(); + int64_t max_j = 1000000 / grpc_test_slowdown_factor(); + for (i = 0; i < max_i; i++) { /* run for a bit - just calculate something random. */ - for (j = 0; j < 1000000 / grpc_test_slowdown_factor(); j++) { + for (j = 0; j < max_j; j++) { r = (r * 17) & ((r - i) | (r * i)); } cpu = gpr_cpu_current_cpu(); -- cgit v1.2.3