[tracker/dbus-fd-experiment-gio: 5/41] Steroids: Add simple bench program



commit 8c618a275408925a9927e15473f0db936cc5d6d8
Author: Adrien Bustany <abustany gnome org>
Date:   Fri May 28 09:28:36 2010 -0400

    Steroids: Add simple bench program

 examples/steroids/Makefile.am |    6 +++-
 examples/steroids/benchmark.c |   73 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 1 deletions(-)
---
diff --git a/examples/steroids/Makefile.am b/examples/steroids/Makefile.am
index 19fe433..a390607 100644
--- a/examples/steroids/Makefile.am
+++ b/examples/steroids/Makefile.am
@@ -13,11 +13,13 @@ INCLUDES =							\
 	$(GIO_CFLAGS)						\
 	$(DBUS_CFLAGS)
 
-noinst_PROGRAMS = steroids-sparql
+noinst_PROGRAMS = steroids-sparql benchmark
 
 steroids_sparql_SOURCES =					\
 	steroids-sparql.c
 
+benchmark_SOURCES= benchmark.c
+
 steroids_sparql_LDADD =						\
        $(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
        $(top_builddir)/src/libtracker-common/libtracker-common.la \
@@ -29,3 +31,5 @@ steroids_sparql_LDADD =						\
        $(GLIB2_LIBS)						\
        -lz							\
        -lm
+
+benchmark_LDADD= $(steroids_sparql_LDADD)
diff --git a/examples/steroids/benchmark.c b/examples/steroids/benchmark.c
new file mode 100644
index 0000000..6792bc2
--- /dev/null
+++ b/examples/steroids/benchmark.c
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libtracker-client/tracker.h>
+
+int
+main (int argc, char **argv)
+{
+	const char *query;
+	TrackerClient *client;
+	GError *error = NULL;
+	GPtrArray *results;
+	TrackerResultIterator *iterator;
+	char buffer[1024*1024];
+	GTimer *timer;
+	int i, j;
+	double time_normal, time_steroids;
+
+	if (argc != 2) {
+		fprintf (stderr, "Usage: %s query\n", argv[0]);
+		exit (1);
+	}
+
+	query = argv[1];
+
+	client = tracker_client_new (0, 0);
+
+	timer = g_timer_new ();
+
+	results = tracker_resources_sparql_query (client, query, &error);
+
+	if (error) {
+		g_critical ("Query error: %s", error->message);
+		g_error_free (error);
+		g_timer_destroy (timer);
+		exit (1);
+	}
+
+	for (i = 0; i < results->len; i++) {
+		GStrv row = g_ptr_array_index (results, i);
+
+		for (j = 0; row[j]; j++) {
+			memcpy (buffer, row[j], g_utf8_strlen (row[j], -1));
+		}
+	}
+
+	time_normal = g_timer_elapsed (timer, NULL);
+
+	g_ptr_array_free (results, TRUE);
+
+	g_timer_start (timer);
+
+	iterator = tracker_resources_sparql_query_iterate (client, query, &error);
+
+	while (tracker_result_iterator_has_next (iterator)) {
+		tracker_result_iterator_next (iterator);
+
+		for (i = 0; i < tracker_result_iterator_n_columns (iterator); i++) {
+			const char *data = tracker_result_iterator_value (iterator, i);
+			memcpy (buffer, data, g_utf8_strlen (data, -1));
+		}
+	}
+
+	time_steroids = g_timer_elapsed (timer, NULL);
+
+	tracker_result_iterator_free (iterator);
+
+	printf ("Normal:   %f seconds\n", time_normal);
+	printf ("Steroids: %f seconds\n", time_steroids);
+	printf ("Speedup:  %f %%\n", 100 * (time_normal/time_steroids - 1));
+
+	return 0;
+}



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