summaryrefslogtreecommitdiff
path: root/lib/find_bit_benchmark.c
diff options
context:
space:
mode:
authorYury Norov <yury.norov@gmail.com>2022-09-18 06:07:14 +0300
committerYury Norov <yury.norov@gmail.com>2022-09-26 22:19:12 +0300
commite3783c805db29c8cb3e8dcc8160f6449da1100e3 (patch)
treeb82e7946018a95bcd73094bf932ffb2b12cb37ca /lib/find_bit_benchmark.c
parent3cea8d475327756066e2a54f0b651bb7284dd448 (diff)
downloadlinux-e3783c805db29c8cb3e8dcc8160f6449da1100e3.tar.xz
lib/bitmap: add tests for find_nth_bit()
Add functional and performance tests for find_nth_bit(). Signed-off-by: Yury Norov <yury.norov@gmail.com>
Diffstat (limited to 'lib/find_bit_benchmark.c')
-rw-r--r--lib/find_bit_benchmark.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c
index db904b57d4b8..10754586403b 100644
--- a/lib/find_bit_benchmark.c
+++ b/lib/find_bit_benchmark.c
@@ -115,6 +115,22 @@ static int __init test_find_last_bit(const void *bitmap, unsigned long len)
return 0;
}
+static int __init test_find_nth_bit(const unsigned long *bitmap, unsigned long len)
+{
+ unsigned long l, n, w = bitmap_weight(bitmap, len);
+ ktime_t time;
+
+ time = ktime_get();
+ for (n = 0; n < w; n++) {
+ l = find_nth_bit(bitmap, len, n);
+ WARN_ON(l >= len);
+ }
+ time = ktime_get() - time;
+ pr_err("find_nth_bit: %18llu ns, %6ld iterations\n", time, w);
+
+ return 0;
+}
+
static int __init test_find_next_and_bit(const void *bitmap,
const void *bitmap2, unsigned long len)
{
@@ -142,6 +158,7 @@ static int __init find_bit_test(void)
test_find_next_bit(bitmap, BITMAP_LEN);
test_find_next_zero_bit(bitmap, BITMAP_LEN);
test_find_last_bit(bitmap, BITMAP_LEN);
+ test_find_nth_bit(bitmap, BITMAP_LEN / 10);
/*
* test_find_first_bit() may take some time, so
@@ -164,6 +181,7 @@ static int __init find_bit_test(void)
test_find_next_bit(bitmap, BITMAP_LEN);
test_find_next_zero_bit(bitmap, BITMAP_LEN);
test_find_last_bit(bitmap, BITMAP_LEN);
+ test_find_nth_bit(bitmap, BITMAP_LEN);
test_find_first_bit(bitmap, BITMAP_LEN);
test_find_first_and_bit(bitmap, bitmap2, BITMAP_LEN);
test_find_next_and_bit(bitmap, bitmap2, BITMAP_LEN);