summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2020-10-14 12:18:07 +0200
committerBastien Nocera <hadess@hadess.net>2020-10-14 12:20:04 +0200
commit06f0e9f8bf9f0474993000de323fefcef5cadd51 (patch)
tree1df1496908e73bb7db13cca3a723128172c4ca33
parentb9a3f6c07c5ac64dd14ddfda73a93790edf47d44 (diff)
downloadgnome-desktop-06f0e9f8bf9f0474993000de323fefcef5cadd51.tar.gz
thumbnail: Print time elapsed when requested during test
-rw-r--r--libgnome-desktop/test-desktop-thumbnail.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libgnome-desktop/test-desktop-thumbnail.c b/libgnome-desktop/test-desktop-thumbnail.c
index f3814de3..e50a3743 100644
--- a/libgnome-desktop/test-desktop-thumbnail.c
+++ b/libgnome-desktop/test-desktop-thumbnail.c
@@ -64,8 +64,10 @@ thumbnail_file (GnomeDesktopThumbnailFactory *factory,
int main (int argc, char **argv)
{
g_autoptr(GnomeDesktopThumbnailFactory) factory = NULL;
+ g_autoptr(GTimer) timer = NULL;
gint num_iterations = 1;
gboolean shared_factory = FALSE;
+ gboolean show_timer = FALSE;
char **filenames = NULL;
int ret = 0;
g_autoptr(GOptionContext) option_context = NULL;
@@ -73,10 +75,13 @@ int main (int argc, char **argv)
const GOptionEntry options[] = {
{ "shared-factory", 's', 0, G_OPTION_ARG_NONE, &shared_factory, "Whether to share the Thumbnail Factory (default: off)", NULL },
{ "num-iterations", 'n', 0, G_OPTION_ARG_INT, &num_iterations, "Number of times to run thumbnail operation (default: 1)", NULL },
+ { "show-timer", 't', 0, G_OPTION_ARG_NONE, &show_timer, "Whether to show time statistics for operations", NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, "[INPUT FILE] [OUTPUT FILE]", NULL },
{ NULL}
};
int i;
+ gdouble first_iter_elapsed = 0.0;
+ gdouble following_elapsed = 0.0;
setlocale (LC_ALL, "");
option_context = g_option_context_new ("");
@@ -97,16 +102,40 @@ int main (int argc, char **argv)
return 1;
}
+ timer = g_timer_new ();
+
for (i = 0; i < num_iterations; i++) {
+ g_timer_start (timer);
+
if (factory == NULL)
factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
if (!thumbnail_file (factory, filenames[0], filenames[1]))
return 1;
+ if (i == 0)
+ first_iter_elapsed = g_timer_elapsed (timer, NULL);
+ else
+ following_elapsed += g_timer_elapsed (timer, NULL);
+
if (!shared_factory)
g_clear_object (&factory);
}
+ if (show_timer) {
+ if (num_iterations == 1) {
+ g_print ("Elapsed time: %d msec\n",
+ (int) (first_iter_elapsed * 1000));
+ } else if (num_iterations > 1) {
+ g_print ("First iteration: %d msec\n",
+ (int) (first_iter_elapsed * 1000));
+ g_print ("Average time: %d msec (%d iterations)\n",
+ (int) (following_elapsed * 1000 / (num_iterations - 1)),
+ num_iterations - 1);
+ } else {
+ g_assert_not_reached ();
+ }
+ }
+
return 0;
}