[PATCHv2 2/2] lib: kstrtox: add performance test case

From: Andy Shevchenko
Date: Mon Jul 18 2011 - 08:58:43 EST


Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
lib/test-kstrtox.c | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c
index d55769d..2da5950 100644
--- a/lib/test-kstrtox.c
+++ b/lib/test-kstrtox.c
@@ -65,6 +65,12 @@ struct test_fail {
} \
}

+static int loop_amount;
+
+module_param(loop_amount, int, 0);
+MODULE_PARM_DESC(loop_amount,
+ "Amount of loops for performance test (0 - no test)");
+
static void __init test_kstrtoull_ok(void)
{
DECLARE_TEST_OK(unsigned long long, struct test_ull);
@@ -707,6 +713,27 @@ static void __init test_kstrtos8_fail(void)
TEST_FAIL(kstrtos8, s8, "%hhd", test_s8_fail);
}

+static void __init test_kstrtox_perf(void)
+{
+ struct timespec ts, ts1, ts2;
+ int count = loop_amount;
+
+ if (!loop_amount)
+ return;
+
+ getnstimeofday(&ts1);
+ while (count--) {
+ test_kstrtoull_ok();
+ test_kstrtoull_fail();
+ }
+ getnstimeofday(&ts2);
+ ts = timespec_sub(ts2, ts1);
+
+ printk(KERN_INFO "kstrox: %d conversions of strings took %lu.%09lu "
+ "seconds\n", loop_amount,
+ (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec);
+}
+
static int __init test_kstrtox_init(void)
{
test_kstrtoull_ok();
@@ -733,6 +760,9 @@ static int __init test_kstrtox_init(void)
test_kstrtou8_fail();
test_kstrtos8_ok();
test_kstrtos8_fail();
+
+ test_kstrtox_perf();
+
return -EINVAL;
}
module_init(test_kstrtox_init);
--
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/