diff options
author | Yuchen Zeng <zyc@google.com> | 2017-03-06 14:20:26 -0800 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2017-03-07 11:32:44 -0800 |
commit | f0d6b88626223e2f8b77072fb628fdcf4a5f87ab (patch) | |
tree | 78587583940fe2e439284e764471dd2786a7f8ab /test/core/support | |
parent | 437cc199abff8eb69a4212d42c89dbb7703eb17d (diff) |
Avoid repetitive division calculations
Diffstat (limited to 'test/core/support')
-rw-r--r-- | test/core/support/cpu_test.c | 7 |
1 files changed, 5 insertions, 2 deletions
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(); |