[Gridflow-cvs] [svn] commit: r3716 - in /trunk/tests: Makefile malloc-test.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Thu May 22 15:37:02 EDT 2008


Author: matju
Date: Thu May 22 15:37:02 2008
New Revision: 3716

Log:
added (non-lazy) calloc test

Modified:
    trunk/tests/Makefile
    trunk/tests/malloc-test.c

Modified: trunk/tests/Makefile
==============================================================================
--- trunk/tests/Makefile (original)
+++ trunk/tests/Makefile Thu May 22 15:37:02 2008
@@ -1,5 +1,7 @@
 all:: malloc-test
 
-malloc-test: malloc-test.c
-	g++ -xc++ malloc-test.c -o malloc-test
+COMMON = Makefile
 
+malloc-test: malloc-test.c $(COMMON)
+	g++ -xc++ -O3 malloc-test.c -o malloc-test
+

Modified: trunk/tests/malloc-test.c
==============================================================================
--- trunk/tests/malloc-test.c (original)
+++ trunk/tests/malloc-test.c Thu May 22 15:37:02 2008
@@ -10,15 +10,27 @@
 	gettimeofday(&t,0);
 	return t.tv_sec*1000000+t.tv_usec;
 }
-
-static void test (size_t n) {
+static void test1 (size_t n) {
 	uint64 t = gf_timeofday();
 	for (int i=0; i<10000; i++) free(malloc(n));
 	t = gf_timeofday() - t;
 	printf("10000 mallocs of %7ld bytes takes %7ld us (%f us/malloc)\n",n,(long)t,t/(float)10000);
 }
-
+static void test2 (size_t n) {
+	uint64 t = gf_timeofday();
+	// the real calloc is lazy, let's try a manual (strict) calloc
+	//for (int i=0; i<10000; i++) free(calloc(1,n));
+	for (int i=0; i<10000; i++) {
+		long *p = (long *)malloc(n);
+		size_t nn=n/sizeof(long);
+		for (size_t j=0; j<nn; j++) p[j] = 0;
+		free(p);
+	}
+	t = gf_timeofday() - t;
+	printf("10000 callocs of %7ld bytes takes %7ld us (%f us/calloc)\n",n,(long)t,t/(float)10000);
+}
 int main () {
-	for (int i=0; i<20; i++) {test(4<<i); test(6<<i);}
+	for (int i=0; i<20; i++) {test1(4<<i); test2(4<<i);}
+	//for (int i=0; i<20; i++) test1(4096*(32+i));
 	return 0;
 }



More information about the Gridflow-cvs mailing list