summaryrefslogtreecommitdiff
path: root/source4/torture
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-09-28 06:12:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:25 -0500
commit7cc7c553cb57a8eb0e03b623688709fd417b21e8 (patch)
treea29b1e86a1f0b307b0c846fff8a6c9e0514d726f /source4/torture
parentb2f1a29e4348a5bc34a87d72d526e23e421ed9d5 (diff)
downloadsamba-7cc7c553cb57a8eb0e03b623688709fd417b21e8.tar.gz
samba-7cc7c553cb57a8eb0e03b623688709fd417b21e8.tar.bz2
samba-7cc7c553cb57a8eb0e03b623688709fd417b21e8.zip
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)
Diffstat (limited to 'source4/torture')
-rw-r--r--source4/torture/local/talloc.c55
1 files changed, 55 insertions, 0 deletions
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;
}