[gtksourceview/wip/undo-redo: 14/16] Test UndoManager performances
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/undo-redo: 14/16] Test UndoManager performances
- Date: Tue, 9 Sep 2014 21:26:01 +0000 (UTC)
commit 3d416ee70a273f957093eb11d0e06389367e09c9
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Sep 9 18:37:58 2014 +0200
Test UndoManager performances
And the results are....
Old implementation based on a GPtrArray:
Undo/Redo 10000 actions: 0.486454 seconds.
Undo/Redo 100000 actions: 4.822937 seconds.
New implementation based on GQueues (see next commits):
Undo/Redo 10000 actions: 0.494246 seconds.
Undo/Redo 100000 actions: 4.903951 seconds.
So the difference is small, it's linear with the number of undo's, which
means that an undo or redo is a O(1) operation. It was not the case with
the older implementation based on GList, because GList was not used
correctly (g_list_nth() was called on each undo or redo, because the
location in the history was not stored with a GList node, but with a
gint index).
tests/Makefile.am | 3 +
tests/test-undo-manager-performances.c | 104 ++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 003d2fc..a7532a0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,6 +52,9 @@ test_search_LDADD = \
TEST_PROGS += test-search-performances
test_search_performances_SOURCES = test-search-performances.c
+TEST_PROGS += test-undo-manager-performances
+test_undo_manager_performances_SOURCES = test-undo-manager-performances.c
+
TEST_PROGS += test-widget
test_widget_SOURCES = test-widget.c
nodist_test_widget_SOURCES = test-widget-resources.c
diff --git a/tests/test-undo-manager-performances.c b/tests/test-undo-manager-performances.c
new file mode 100644
index 0000000..c08a6af
--- /dev/null
+++ b/tests/test-undo-manager-performances.c
@@ -0,0 +1,104 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/* test-undo-manager-performances.c
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <gtksourceview/gtksource.h>
+
+#define NB_LINES 100000
+
+/* Returns the number of undo's. */
+static gint
+test_undo_redo (GtkSourceBuffer *buffer,
+ gint max_actions)
+{
+ gint nb_actions;
+ gint i;
+
+ for (nb_actions = 0; nb_actions < max_actions; nb_actions++)
+ {
+ if (gtk_source_buffer_can_undo (buffer))
+ {
+ gtk_source_buffer_undo (buffer);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ for (i = 0; i < nb_actions; i++)
+ {
+ g_assert (gtk_source_buffer_can_redo (buffer));
+ gtk_source_buffer_redo (buffer);
+ }
+
+ return nb_actions;
+}
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ GtkSourceBuffer *source_buffer;
+ GtkTextBuffer *text_buffer;
+ GtkTextIter iter;
+ GTimer *timer;
+ gint nb_actions;
+ gint i;
+
+ gtk_init (&argc, &argv);
+
+ source_buffer = gtk_source_buffer_new (NULL);
+ text_buffer = GTK_TEXT_BUFFER (source_buffer);
+
+ gtk_text_buffer_get_start_iter (text_buffer, &iter);
+
+ for (i = 0; i < NB_LINES; i++)
+ {
+ gtk_text_buffer_begin_user_action (text_buffer);
+
+ gtk_text_buffer_insert (text_buffer,
+ &iter,
+ "A line of text to fill the text buffer. Is it long enough?\n",
+ -1);
+
+ gtk_text_buffer_end_user_action (text_buffer);
+ }
+
+ timer = g_timer_new ();
+ nb_actions = test_undo_redo (source_buffer, NB_LINES / 10);
+ g_timer_stop (timer);
+
+ g_print ("Undo/Redo %d actions: %lf seconds.\n",
+ nb_actions,
+ g_timer_elapsed (timer, NULL));
+
+ g_timer_start (timer);
+ nb_actions = test_undo_redo (source_buffer, NB_LINES);
+ g_timer_stop (timer);
+
+ g_print ("Undo/Redo %d actions: %lf seconds.\n",
+ nb_actions,
+ g_timer_elapsed (timer, NULL));
+
+ g_object_unref (source_buffer);
+ g_timer_destroy (timer);
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]