[libgdata] [tests] Add performance and callgrind tests



commit 62fafe938a1dd03d763de1068d69495b3e219ba4
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Jan 24 17:18:55 2010 +0000

    [tests] Add performance and callgrind tests
    
    Add perf and callgrind tests, and add the perf test to the test suite.
    Add some more alloc-fns to the massif test case.

 gdata/tests/Makefile.am |    3 +
 gdata/tests/callgrind   |    3 +
 gdata/tests/massif      |    3 +-
 gdata/tests/perf.c      |  101 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 109 insertions(+), 1 deletions(-)
---
diff --git a/gdata/tests/Makefile.am b/gdata/tests/Makefile.am
index 0688288..4bbc6f4 100644
--- a/gdata/tests/Makefile.am
+++ b/gdata/tests/Makefile.am
@@ -39,6 +39,9 @@ documents_SOURCES		 = documents.c $(TEST_SRCS)
 TEST_PROGS			+= memory
 memory_SOURCES			 = memory.c $(TEST_SRCS)
 
+TEST_PROGS			+= perf
+perf_SOURCES			 = perf.c $(TEST_SRCS)
+
 EXTRA_DIST += \
 	photo.jpg		\
 	sample.ogg		\
diff --git a/gdata/tests/callgrind b/gdata/tests/callgrind
new file mode 100755
index 0000000..a725238
--- /dev/null
+++ b/gdata/tests/callgrind
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+libtool --mode=execute "valgrind --tool=callgrind --callgrind-out-file=callgrind.`date +%s` " ./general
diff --git a/gdata/tests/massif b/gdata/tests/massif
index 9c4104d..a6e8eb2 100755
--- a/gdata/tests/massif
+++ b/gdata/tests/massif
@@ -2,4 +2,5 @@
 
 libtool --mode=execute "valgrind --tool=massif --alloc-fn=g_slice_new --alloc-fn=g_slice_alloc --alloc-fn=g_slice_alloc0 \
 			--alloc-fn=g_malloc --alloc-fn=g_realloc --alloc-fn=g_try_malloc --alloc-fn=g_malloc0 \
-			--alloc-fn=g_object_new --alloc-fn=g_object_new_valist --alloc-fn=g_object_newv" ./memory
+			--alloc-fn=g_object_new --alloc-fn=g_object_new_valist --alloc-fn=g_object_newv --alloc-fn=g_type_init
+			--alloc-fn=profiler_calloc --alloc-fn=profiler_malloc --alloc-fn=profiler_realloc" ./general
diff --git a/gdata/tests/perf.c b/gdata/tests/perf.c
new file mode 100644
index 0000000..a783e18
--- /dev/null
+++ b/gdata/tests/perf.c
@@ -0,0 +1,101 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Philip Withnall 2010 <philip tecnocode co uk>
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+
+#include "gdata.h"
+#include "common.h"
+
+static void
+test_parse_feed (void)
+{
+	GDataFeed *feed;
+	GError *error = NULL;
+
+	feed = GDATA_FEED (gdata_parsable_new_from_xml (GDATA_TYPE_FEED,
+		"<feed xmlns='http://www.w3.org/2005/Atom' "
+		      "xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' "
+		      "xmlns:gd='http://schemas.google.com/g/2005' "
+		      "gd:etag='W/\"D08FQn8-eil7ImA9WxZbFEw.\"'>"
+			"<id>http://example.com/id</id>"
+			"<updated>2009-02-25T14:07:37.880860Z</updated>"
+			"<title type='text'>Test feed</title>"
+			"<subtitle type='text'>Test subtitle</subtitle>"
+			"<logo>http://example.com/logo.png</logo>"
+			"<icon>http://example.com/icon.png</icon>"
+			"<link rel='alternate' type='text/html' href='http://alternate.example.com/'/>"
+			"<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://example.com/id'/>"
+			"<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://example.com/post'/>"
+			"<link rel='self' type='application/atom+xml' href='http://example.com/id'/>"
+			"<category scheme='http://example.com/categories' term='feed'/>"
+			"<author>"
+				"<name>Joe Smith</name>"
+				"<email>j smith example com</email>"
+			"</author>"
+			"<generator version='0.6' uri='http://example.com/'>Example Generator</generator>"
+			"<openSearch:totalResults>2</openSearch:totalResults>"
+			"<openSearch:startIndex>0</openSearch:startIndex>"
+			"<openSearch:itemsPerPage>50</openSearch:itemsPerPage>"
+			"<entry>"
+				"<id>entry1</id>"
+				"<title type='text'>Testing unhandled XML</title>"
+				"<updated>2009-01-25T14:07:37.880860Z</updated>"
+				"<published>2009-01-23T14:06:37.880860Z</published>"
+				"<content type='text'>Here we test unhandled XML elements.</content>"
+			"</entry>"
+			"<entry>"
+				"<id>entry2</id>"
+				"<title type='text'>Testing unhandled XML 2</title>"
+				"<updated>2009-02-25T14:07:37.880860Z</updated>"
+				"<published>2009-02-23T14:06:37.880860Z</published>"
+				"<content type='text'>Here we test unhandled XML elements again.</content>"
+			"</entry>"
+		"</feed>", -1, &error));
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_FEED (feed));
+	g_clear_error (&error);
+
+	g_object_unref (feed);
+}
+
+int
+main (int argc, char *argv[])
+{
+	GTimeVal start_time, end_time;
+	guint i;
+	gdouble total_time;
+
+	#define ITERATIONS 10000
+
+	g_type_init ();
+	g_thread_init (NULL);
+
+	/* Test feed parsing time */
+	g_get_current_time (&start_time);
+	for (i = 0; i < ITERATIONS; i++)
+		test_parse_feed ();
+	g_get_current_time (&end_time);
+
+	total_time = (gdouble) (end_time.tv_sec - start_time.tv_sec) + (gdouble) (end_time.tv_usec - start_time.tv_usec) / (gdouble) G_USEC_PER_SEC;
+
+	g_message ("Parsing a feed %u times took:\n * Total: %fs\n * Per iteration: %fs",
+	           ITERATIONS, total_time, total_time / (gdouble) ITERATIONS);
+
+	return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]