[gnome-desktop] pnp-ids: Add loop for speed testing the ID fetching



commit 6893c9a51200ce630af97fbda58eda678bae920b
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jun 20 17:40:28 2012 +0100

    pnp-ids: Add loop for speed testing the ID fetching
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=590059

 libgnome-desktop/test-pnp-ids.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/libgnome-desktop/test-pnp-ids.c b/libgnome-desktop/test-pnp-ids.c
index f357289..2f6ef4e 100644
--- a/libgnome-desktop/test-pnp-ids.c
+++ b/libgnome-desktop/test-pnp-ids.c
@@ -22,6 +22,8 @@
 
 #include <libgnome-desktop/gnome-pnp-ids.h>
 
+#define NUM_ITERS 500 * 1000
+
 static void
 show_vendor (GnomePnpIds *ids, const char *id)
 {
@@ -40,6 +42,30 @@ main (int argc, char *argv[])
 	g_type_init ();
 
 	ids = gnome_pnp_ids_new ();
+
+	if (argc == 2 &&
+	    g_str_equal (argv[1], "--timed")) {
+		GTimer *timer;
+		gdouble elapsed;
+
+		timer = g_timer_new ();
+
+		for (i = 0; i < NUM_ITERS; i++) {
+			char *vendor;
+			vendor = gnome_pnp_ids_get_pnp_id (ids, "ZZZ");
+			g_free (vendor);
+		}
+
+		elapsed = g_timer_elapsed (timer, NULL);
+		g_timer_destroy (timer);
+
+		g_message ("%d iterations took %lf seconds", NUM_ITERS, elapsed);
+		g_object_unref (ids);
+
+		return 0;
+	}
+
+
 	for (i = 1; i < argc; i++)
 		show_vendor (ids, argv[i]);
 	if (argc < 2) {



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