diff options
author | Benjamin Otte <otte@redhat.com> | 2016-12-25 06:18:42 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-12-25 06:23:12 +0100 |
commit | eacf7257784ac92d71803b9296e1d510a27a9801 (patch) | |
tree | eb39088d1432ae1320eac5bc925301987ec50794 /tests/rendernode.c | |
parent | c99b46c46d393d6c764f2dbefaeec89b8c6fd16c (diff) | |
download | gtk+-eacf7257784ac92d71803b9296e1d510a27a9801.tar.gz |
tests: Add a --runs argument to rendernode
This way we can rerun fast tests lots of times - not so much for
averaging times, but more for sysprof'ing.
Diffstat (limited to 'tests/rendernode.c')
-rw-r--r-- | tests/rendernode.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/tests/rendernode.c b/tests/rendernode.c index 73f67db2b8..4388e79ff4 100644 --- a/tests/rendernode.c +++ b/tests/rendernode.c @@ -3,11 +3,13 @@ static gboolean benchmark = FALSE; static gboolean dump_variant = FALSE; static gboolean fallback = FALSE; +static int runs; static GOptionEntry options[] = { { "benchmark", 'b', 0, G_OPTION_ARG_NONE, &benchmark, "Time operations", NULL }, { "dump-variant", 'd', 0, G_OPTION_ARG_NONE, &dump_variant, "Dump GVariant structure", NULL }, { "fallback", '\0', 0, G_OPTION_ARG_NONE, &fallback, "Draw node without a renderer", NULL }, + { "runs", 'r', 0, G_OPTION_ARG_INT, &runs, "Render the test N times", "N" }, { NULL } }; @@ -21,6 +23,7 @@ main(int argc, char **argv) gint64 start, end; char *contents; gsize len; + int run; if (!gtk_init_with_args (&argc, &argv, "NODE-FILE PNG-FILE", options, NULL, &error)) @@ -78,11 +81,21 @@ main(int argc, char **argv) cr = cairo_create (surface); cairo_translate (cr, - bounds.origin.x, - bounds.origin.y); - start = g_get_monotonic_time (); - gsk_render_node_draw (node, cr); - end = g_get_monotonic_time (); - if (benchmark) - g_print ("Rendered fallback in %.4gs\n", (double) (end - start) / G_USEC_PER_SEC); + for (run = 0; run < runs; run++) + { + if (run > 0) + { + cairo_save (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr); + cairo_restore (cr); + } + start = g_get_monotonic_time (); + gsk_render_node_draw (node, cr); + end = g_get_monotonic_time (); + if (benchmark) + g_print ("Run %d: Rendered fallback in %.4gs\n", run, (double) (end - start) / G_USEC_PER_SEC); + } cairo_destroy (cr); } @@ -95,11 +108,17 @@ main(int argc, char **argv) window = gdk_window_new_toplevel (gdk_display_get_default(), 0, 10 , 10); renderer = gsk_renderer_new_for_window (window); - start = g_get_monotonic_time (); - texture = gsk_renderer_render_texture (renderer, node, NULL); - end = g_get_monotonic_time (); - if (benchmark) - g_print ("Rendered using %s in %.4gs\n", G_OBJECT_TYPE_NAME (renderer), (double) (end - start) / G_USEC_PER_SEC); + for (run = 0; run < runs; run++) + { + if (run > 0) + gsk_texture_unref (texture); + start = g_get_monotonic_time (); + texture = gsk_renderer_render_texture (renderer, node, NULL); + end = g_get_monotonic_time (); + if (benchmark) + g_print ("Run %u: Rendered using %s in %.4gs\n", run, G_OBJECT_TYPE_NAME (renderer), (double) (end - start) / G_USEC_PER_SEC); + } + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, gsk_texture_get_width (texture), gsk_texture_get_height (texture)); |