[tracker/dbus-fd-experiment-squashed: 5/6] Steroids: Add simple benchmark programs
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/dbus-fd-experiment-squashed: 5/6] Steroids: Add simple benchmark programs
- Date: Fri, 4 Jun 2010 01:19:37 +0000 (UTC)
commit 88f8be56b88e469583a372a14a6380436c1496ca
Author: Adrien Bustany <abustany gnome org>
Date: Fri May 28 09:28:36 2010 -0400
Steroids: Add simple benchmark programs
examples/steroids/Makefile.am | 12 +++++-
examples/steroids/benchmark-update.c | 73 ++++++++++++++++++++++++++++++++++
examples/steroids/benchmark.c | 73 ++++++++++++++++++++++++++++++++++
3 files changed, 157 insertions(+), 1 deletions(-)
---
diff --git a/examples/steroids/Makefile.am b/examples/steroids/Makefile.am
index 55abdbb..7824e77 100644
--- a/examples/steroids/Makefile.am
+++ b/examples/steroids/Makefile.am
@@ -15,11 +15,17 @@ INCLUDES = \
noinst_PROGRAMS = \
steroids-sparql \
- steroids-sparql-async
+ steroids-sparql-async \
+ benchmark \
+ benchmark-update
steroids_sparql_SOURCES = \
steroids-sparql.c
+benchmark_SOURCES= benchmark.c
+
+benchmark_update_SOURCES=benchmark-update.c
+
steroids_sparql_LDADD = \
$(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
@@ -33,3 +39,7 @@ steroids_sparql_LDADD = \
-lm
steroids_sparql_async_LDADD= $(steroids_sparql_LDADD)
+
+benchmark_LDADD= $(steroids_sparql_LDADD)
+
+benchmark_update_LDADD= $(steroids_sparql_LDADD)
diff --git a/examples/steroids/benchmark-update.c b/examples/steroids/benchmark-update.c
new file mode 100644
index 0000000..4fb76bb
--- /dev/null
+++ b/examples/steroids/benchmark-update.c
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libtracker-client/tracker.h>
+
+#define N_TRIES 500
+
+int
+main (int argc, char **argv)
+{
+ const char *query;
+ TrackerClient *client;
+ GError *error = NULL;
+ GTimer *timer;
+ int i;
+ 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);
+
+ /* Run a first time to warm cache */
+ for (i = 0; i < N_TRIES; i++) {
+ tracker_resources_sparql_update (client, query, &error);
+
+ if (error) {
+ g_critical ("Query error: %s", error->message);
+ g_error_free (error);
+ exit (1);
+ }
+ }
+
+ timer = g_timer_new ();
+
+ for (i = 0; i < N_TRIES; i++) {
+ tracker_resources_sparql_update (client, query, &error);
+
+ if (error) {
+ g_critical ("Query error: %s", error->message);
+ g_error_free (error);
+ g_timer_destroy (timer);
+ exit (1);
+ }
+ }
+
+ time_normal = g_timer_elapsed (timer, NULL);
+
+ g_timer_start (timer);
+
+ for (i = 0; i < N_TRIES; i++) {
+ tracker_resources_sparql_update_fast (client, query, &error);
+
+ if (error) {
+ g_critical ("Query error: %s", error->message);
+ g_error_free (error);
+ g_timer_destroy (timer);
+ exit (1);
+ }
+ }
+
+ time_steroids = g_timer_elapsed (timer, NULL);
+
+ printf ("Normal: %f seconds\n", time_normal/N_TRIES);
+ printf ("Steroids: %f seconds\n", time_steroids/N_TRIES);
+ printf ("Speedup: %f %%\n", 100 * (time_normal/time_steroids - 1));
+
+ return 0;
+}
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]