]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: lru: use a xorshift generator in the testing code
authorWilly Tarreau <w@1wt.eu>
Wed, 26 Jan 2022 10:06:07 +0000 (11:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 27 Jan 2022 15:28:10 +0000 (16:28 +0100)
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.

src/lru.c

index d58b188861307fede53e1df58d5b5c7bc036ec62..f092588e3deb59f8c5c4dccf7e33c74b0fb24d14 100644 (file)
--- 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));