summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2018-04-06 14:40:36 +0200
committerTimm Bäder <mail@baedert.org>2018-06-03 11:47:22 +0200
commit0694c2a65e5f1d73710f1e6a5124c3413da3f770 (patch)
tree0dade23b94769a76fd4e2b146248816bd4044403
parent3279901e64bff291c393fe7bff53f0049264cd7d (diff)
downloadgtk+-0694c2a65e5f1d73710f1e6a5124c3413da3f770.tar.gz
benchmarks: Add simple css benchmark
-rw-r--r--benchmarks/css.c77
-rw-r--r--benchmarks/meson.build1
2 files changed, 78 insertions, 0 deletions
diff --git a/benchmarks/css.c b/benchmarks/css.c
new file mode 100644
index 0000000000..3cf60474de
--- /dev/null
+++ b/benchmarks/css.c
@@ -0,0 +1,77 @@
+#include <gtk/gtk.h>
+#include "benchmark.h"
+
+/* Command line options */
+const char *profile_benchmark_name = NULL;
+static GOptionEntry options[] = {
+ { "profile", 'p', 0, G_OPTION_ARG_STRING, &profile_benchmark_name, "Benchmark name to profile using callgrind", NULL },
+ { NULL }
+};
+
+
+static void
+css_compute_benchmark (Benchmark *b,
+ gsize size,
+ gpointer user_data)
+{
+ GtkWidget **widgets = g_malloc (sizeof (GtkWidget *) * size);
+ GtkWidget *box;
+ GtkWidget *scroller;
+ GtkWidget *window;
+ GdkFrameClock *frame_clock;
+ guint i;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+
+ for (i = 0; i < size; i ++)
+ {
+ widgets[i] = gtk_label_new ("foo");
+ /*widgets[i] = gtk_button_new ();*/
+ gtk_container_add (GTK_CONTAINER (box), widgets[i]);
+ }
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ scroller = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (scroller), box);
+ gtk_container_add (GTK_CONTAINER (window), scroller);
+
+ gtk_widget_realize (window);
+ frame_clock = gtk_widget_get_frame_clock (window);
+ g_assert (frame_clock != NULL);
+
+ gtk_widget_show (window);
+ g_signal_connect (frame_clock, "layout", G_CALLBACK (gtk_main_quit), NULL);
+
+ benchmark_start (b);
+ gtk_main ();
+ benchmark_stop (b);
+
+ gtk_widget_hide (window);
+ gtk_widget_destroy (window);
+
+ g_free (widgets);
+}
+
+
+int
+main (int argc, char **argv)
+{
+ BenchmarkSuite suite;
+ GOptionContext *option_context;
+ GError *error = NULL;
+
+ option_context = g_option_context_new ("");
+ g_option_context_add_main_entries (option_context, options, NULL);
+ if (!g_option_context_parse (option_context, &argc, &argv, &error))
+ {
+ g_printerr ("Option parsing failed: %s\n", error->message);
+ return 1;
+ }
+
+ benchmark_suite_init (&suite, profile_benchmark_name);
+ gtk_init ();
+
+ benchmark_suite_add (&suite, "css compute", 10000, css_compute_benchmark, NULL);
+
+ return benchmark_suite_run (&suite);
+}
diff --git a/benchmarks/meson.build b/benchmarks/meson.build
index 51397e3d6e..3705618772 100644
--- a/benchmarks/meson.build
+++ b/benchmarks/meson.build
@@ -2,6 +2,7 @@
# benchmark name, optional extra sources
gtk_benchmarks = [
['containers'],
+ ['css'],
]
foreach b : gtk_benchmarks