[evolution-data-server/openismus-work] Added some profiling to test-ebook-get-book-view-uid-only.c
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work] Added some profiling to test-ebook-get-book-view-uid-only.c
- Date: Mon, 13 Jun 2011 20:57:36 +0000 (UTC)
commit 1247d3cd2b15a82e660a682a8a2d5631f9e932e0
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Mon Jun 13 17:57:45 2011 +0900
Added some profiling to test-ebook-get-book-view-uid-only.c
Now compare the loading time of a fully populated book view
vs a book view with only the UIDs.
.../ebook/test-ebook-get-book-view-uid-only.c | 172 ++++++++++++++++++--
1 files changed, 154 insertions(+), 18 deletions(-)
---
diff --git a/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c b/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
index d149244..cedb7c5 100644
--- a/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
+++ b/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
@@ -5,23 +5,70 @@
#include "ebook-test-utils.h"
+#define N_TEST_CONTACTS 1000
+
+/* If COMPARE_PERFORMANCE is set, only print a performance comparison, otherwise print contacts */
+#define COMPARE_PERFORMANCE 1
+#define BEEFY_VCARDS 1
+
+
+#if COMPARE_PERFORMANCE
+# define SETUP_TIMER(timer) GTimer *timer = g_timer_new ();
+# define START_TIMER(timer) g_timer_start (timer);
+# define STOP_TIMER(timer) g_timer_stop (timer);
+# define PRINT_TIMER(timer, activity) \
+ test_print ("%s finished in %02.6f seconds\n", activity, g_timer_elapsed (timer, NULL));
+#else
+# define SETUP_TIMER(timer)
+# define START_TIMER(timer)
+# define STOP_TIMER(timer)
+# define PRINT_TIMER(timer, activity)
+#endif
+
+
static GMainLoop *loop;
+#if !COMPARE_PERFORMANCE
+static void
+print_contact (EContact *contact)
+{
+ GList *emails, *e;
+
+ test_print ("Contact: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_FULL_NAME));
+ test_print ("UID: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_UID));
+ test_print ("Email addresses:\n");
+
+ emails = e_contact_get (contact, E_CONTACT_EMAIL);
+ for (e = emails; e; e = e->next) {
+ test_print ("\t%s\n", (gchar *)e->data);
+ }
+ g_list_foreach (emails, (GFunc)g_free, NULL);
+ g_list_free (emails);
+
+ test_print ("\n");
+}
+#endif
+
static void
contacts_added (EBookView *book_view, const GList *contacts)
{
GList *l;
+ gboolean uid_only;
+
+ uid_only = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (book_view), "uid-only"));
for (l = (GList*)contacts; l; l = l->next) {
EContact *contact = l->data;
- test_print ("UID: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_UID));
+#if !COMPARE_PERFORMANCE
+ print_contact (contact);
+#endif
- if (e_contact_get_const (contact, E_CONTACT_FULL_NAME) != NULL) {
- g_warning ("received contact name `%s' when only the uid was requested",
- (gchar *)e_contact_get_const (contact, E_CONTACT_FULL_NAME));
- exit(1);
- }
+ if (uid_only && e_contact_get_const (contact, E_CONTACT_FULL_NAME) != NULL)
+ g_error ("received contact name `%s' when only the uid was requested",
+ (gchar *)e_contact_get_const (contact, E_CONTACT_FULL_NAME));
+ else if (!uid_only && e_contact_get_const (contact, E_CONTACT_FULL_NAME) == NULL)
+ g_error ("expected contact name missing");
}
}
@@ -58,6 +105,8 @@ get_book_view_cb (EBookTestClosure *closure)
{
g_assert (closure->view);
+ g_object_set_data (G_OBJECT (closure->view), "uid-only", closure->user_data);
+
setup_and_start_view (closure->view);
}
@@ -65,13 +114,64 @@ static void
setup_book (EBook **book_out)
{
EBook *book;
+ gint i, j;
book = ebook_test_utils_book_new_temp (NULL);
ebook_test_utils_book_open (book, FALSE);
- ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", NULL);
- ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-2", NULL);
- ebook_test_utils_book_add_contact_from_test_case_verify (book, "name-only", NULL);
+ for (i = 0; i < N_TEST_CONTACTS; i++)
+ {
+ EContact *contact = e_contact_new ();
+ EContact *final;
+ const gchar *uid;
+ gchar *name = g_strdup_printf ("Contact #%d", i + 1);
+ gchar *emails[5] = {
+ g_strdup_printf ("contact%d first email com", i),
+ g_strdup_printf ("contact%d second email com", i),
+ g_strdup_printf ("contact%d third email com", i),
+ g_strdup_printf ("contact%d fourth email com", i),
+ NULL
+ };
+
+ e_contact_set (contact, E_CONTACT_FULL_NAME, name);
+ e_contact_set (contact, E_CONTACT_NICKNAME, name);
+
+ /* Fill some emails */
+ for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_EMAIL_1]);
+
+#if BEEFY_VCARDS
+ /* Fill some other random stuff */
+ for (j = E_CONTACT_IM_AIM_HOME_1; j < (E_CONTACT_IM_AIM_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_HOME_1]);
+ for (j = E_CONTACT_IM_AIM_WORK_1; j < (E_CONTACT_IM_AIM_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_WORK_1]);
+ for (j = E_CONTACT_IM_GROUPWISE_HOME_1; j < (E_CONTACT_IM_GROUPWISE_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_HOME_1]);
+ for (j = E_CONTACT_IM_GROUPWISE_WORK_1; j < (E_CONTACT_IM_GROUPWISE_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_WORK_1]);
+ for (j = E_CONTACT_IM_JABBER_HOME_1; j < (E_CONTACT_IM_JABBER_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_HOME_1]);
+ for (j = E_CONTACT_IM_JABBER_WORK_1; j < (E_CONTACT_IM_JABBER_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_WORK_1]);
+ for (j = E_CONTACT_IM_YAHOO_HOME_1; j < (E_CONTACT_IM_YAHOO_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_HOME_1]);
+ for (j = E_CONTACT_IM_YAHOO_WORK_1; j < (E_CONTACT_IM_YAHOO_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_WORK_1]);
+#endif
+
+ uid = ebook_test_utils_book_add_contact (book, contact);
+ final = ebook_test_utils_book_get_contact (book, uid);
+
+ /* verify the contact was added "successfully" (not thorough) */
+ g_assert (ebook_test_utils_contacts_are_equal_shallow (contact, contact));
+
+ g_free (name);
+ for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++)
+ g_free (emails[j - E_CONTACT_EMAIL_1]);
+
+ g_object_unref (contact);
+ }
*book_out = book;
}
@@ -83,40 +183,76 @@ main (gint argc, gchar **argv)
EBookQuery *query;
EBookView *view;
GList requested_field = { 0, };
+ SETUP_TIMER (timer);
requested_field.data = (gpointer)e_contact_field_name (E_CONTACT_UID);
g_type_init ();
+ setup_book (&book);
/*
- * Sync version
+ * Sync version with all data
*/
- setup_book (&book);
query = e_book_query_any_field_contains ("");
- ebook_test_utils_book_get_book_view (book, query, &requested_field, &view);
+ ebook_test_utils_book_get_book_view (book, query, NULL, &view);
+ g_object_set_data (G_OBJECT (view), "uid-only", GINT_TO_POINTER (FALSE));
+ e_book_query_unref (query);
+
+ START_TIMER (timer);
setup_and_start_view (view);
+ loop = g_main_loop_new (NULL, TRUE);
+ g_main_loop_run (loop);
+ STOP_TIMER (timer);
+ PRINT_TIMER (timer, "Loading all data from book view synchronously");
- test_print ("successfully set up the book view\n");
+ /*
+ * Sync version with uids only
+ */
+ //setup_book (&book);
+ query = e_book_query_any_field_contains ("");
+ ebook_test_utils_book_get_book_view (book, query, &requested_field, &view);
+ g_object_set_data (G_OBJECT (view), "uid-only", GINT_TO_POINTER (TRUE));
+ e_book_query_unref (query);
+ START_TIMER (timer);
+ setup_and_start_view (view);
loop = g_main_loop_new (NULL, TRUE);
g_main_loop_run (loop);
+ STOP_TIMER (timer);
+ PRINT_TIMER (timer, "Loading only uids from book view synchronously");
+
+ /*
+ * Async version all data
+ */
+ query = e_book_query_any_field_contains ("");
+
+ loop = g_main_loop_new (NULL, TRUE);
+ START_TIMER (timer);
+ ebook_test_utils_book_async_get_book_view (book, query, NULL,
+ (GSourceFunc) get_book_view_cb, GINT_TO_POINTER (FALSE));
+
+ g_main_loop_run (loop);
+ STOP_TIMER (timer);
+ PRINT_TIMER (timer, "Loading all data from book view asynchronously");
e_book_query_unref (query);
- ebook_test_utils_book_remove (book);
/*
- * Async version
+ * Async version only uids
*/
- setup_book (&book);
query = e_book_query_any_field_contains ("");
loop = g_main_loop_new (NULL, TRUE);
+ START_TIMER (timer);
ebook_test_utils_book_async_get_book_view (book, query, &requested_field,
- (GSourceFunc) get_book_view_cb, loop);
+ (GSourceFunc) get_book_view_cb, GINT_TO_POINTER (TRUE));
g_main_loop_run (loop);
-
+ STOP_TIMER (timer);
+ PRINT_TIMER (timer, "Loading only uids from book view asynchronously");
e_book_query_unref (query);
+
+
ebook_test_utils_book_remove (book);
return 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]