From 7cc7c553cb57a8eb0e03b623688709fd417b21e8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 28 Sep 2004 06:12:07 +0000 Subject: r2711: added a simple talloc speed tester. I get the following on my laptop: MEASURING TALLOC VS MALLOC SPEED talloc: 279154 ops/sec malloc: 318758 ops/sec which I think is an acceptable overhead for the increased functionality (This used to be commit 91669ea830c16db2730c5e43a7cad26d9db5c585) --- source4/torture/local/talloc.c | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'source4/torture/local') diff --git a/source4/torture/local/talloc.c b/source4/torture/local/talloc.c index 49cdc958b0..4c353ecbbd 100644 --- a/source4/torture/local/talloc.c +++ b/source4/torture/local/talloc.c @@ -22,6 +22,19 @@ #include "includes.h" +static struct timeval tp1,tp2; + +static void start_timer(void) +{ + gettimeofday(&tp1,NULL); +} + +static double end_timer(void) +{ + gettimeofday(&tp2,NULL); + return((tp2.tv_sec - tp1.tv_sec) + + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); +} /* test references @@ -101,6 +114,47 @@ static BOOL test_ref2(void) return True; } +/* + measure the speed of talloc versus malloc +*/ +static BOOL test_speed(void) +{ + void *ctx = talloc(NULL, 0); + uint_t count; + + printf("MEASURING TALLOC VS MALLOC SPEED\n"); + + start_timer(); + count = 0; + do { + void *p1, *p2, *p3; + p1 = talloc(ctx, count); + p2 = talloc_strdup(p1, "foo bar"); + p3 = talloc(p1, 300); + talloc_free(p1); + count += 3; + } while (end_timer() < 5.0); + + printf("talloc: %.0f ops/sec\n", count/end_timer()); + + start_timer(); + count = 0; + do { + void *p1, *p2, *p3; + p1 = malloc(count); + p2 = strdup("foo bar"); + p3 = malloc(300); + free(p1); + free(p2); + free(p3); + count += 3; + } while (end_timer() < 5.0); + + printf("malloc: %.0f ops/sec\n", count/end_timer()); + + return True; +} + BOOL torture_local_talloc(int dummy) { @@ -110,6 +164,7 @@ BOOL torture_local_talloc(int dummy) ret &= test_ref1(); ret &= test_ref2(); + ret &= test_speed(); return True; } -- cgit