From: Willy Tarreau Date: Wed, 26 Jan 2022 10:06:07 +0000 (+0100) Subject: DEBUG: lru: use a xorshift generator in the testing code X-Git-Tag: v2.6-dev1~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8e92738ffde650a819f6bb05cb637dea50af9b70;p=thirdparty%2Fhaproxy.git DEBUG: lru: use a xorshift generator in the testing code The standalone testing code used to rely on rand(), but switching to a xorshift generator speeds up the test by 7% which is important to accurately measure the real impact of the LRU code itself. --- diff --git a/src/lru.c b/src/lru.c index d58b188861..f092588e3d 100644 --- a/src/lru.c +++ b/src/lru.c @@ -262,6 +262,17 @@ static long get_value(struct lru64_head *lru, long a) return a; } +static inline unsigned int statistical_prng() +{ + static unsigned int statistical_prng_state = 0x12345678; + unsigned int x = statistical_prng_state; + + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + return statistical_prng_state = x; +} + /* pass #of loops in argv[1] and set argv[2] to something to use the LRU */ int main(int argc, char **argv) { @@ -281,7 +292,7 @@ int main(int argc, char **argv) ret = 0; for (loops = 0; loops < total; loops++) { - ret += get_value(lru, rand() & 65535); + ret += get_value(lru, statistical_prng() & 65535); } /* just for accuracy control */ printf("ret=%llx, hits=%d, misses=%d (%d %% hits)\n", ret, total-misses, misses, (int)((float)(total-misses) * 100.0 / total));