svn commit: samba r2711 - in branches/SAMBA_4_0/source/torture/local: .

tridge at samba.org tridge at samba.org
Tue Sep 28 06:12:07 GMT 2004


Author: tridge
Date: 2004-09-28 06:12:07 +0000 (Tue, 28 Sep 2004)
New Revision: 2711

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source/torture/local&rev=2711&nolog=1

Log:
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

Modified:
   branches/SAMBA_4_0/source/torture/local/talloc.c


Changeset:
Modified: branches/SAMBA_4_0/source/torture/local/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/torture/local/talloc.c	2004-09-28 05:44:59 UTC (rev 2710)
+++ branches/SAMBA_4_0/source/torture/local/talloc.c	2004-09-28 06:12:07 UTC (rev 2711)
@@ -22,7 +22,20 @@
 
 #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,7 +114,48 @@
 	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) 
 {
 	BOOL ret = True;
@@ -110,6 +164,7 @@
 
 	ret &= test_ref1();
 	ret &= test_ref2();
+	ret &= test_speed();
 
 	return True;
 }



More information about the samba-cvs mailing list