[gxml] Performance tests using GDocumento to test TwDocument



commit 5ced70b740578dfd88402c61e6f9038824088e46
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Feb 22 16:42:08 2016 -0600

    Performance tests using GDocumento to test TwDocument
    
    * Tests show less memory usage for GDocument Vs. xDocument

 NEWS                           |    4 ++
 gxml/GXmlAttribute.vala        |    2 -
 gxml/GXmlElement.vala          |    2 -
 gxml/GXmlHashMapAttr.vala      |    2 -
 gxml/SerializableProperty.vala |    4 +--
 gxml/TwDocument.vala           |    5 ---
 gxml/libxml-Element.vala       |    1 -
 gxml/libxml-NamedAttrMap.vala  |    2 -
 test/gxml-performance.vala     |   72 ++++++++++++++++++++++++++++-----------
 9 files changed, 56 insertions(+), 38 deletions(-)
---
diff --git a/NEWS b/NEWS
index 5d26193..73ce562 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@ Version 0.9.1
 ===============
 
 * Added GXml.Node.parent property
+* Performance measuring: GDocument equivalent to xDocument
+* Memory usage: GDocument 42% less memory
+* Memory for de/serialization using GDocument+TwDocument Vs.
+  xDocument+TwDocument improved using 63% less memory
 
 
 ===============
diff --git a/gxml/GXmlAttribute.vala b/gxml/GXmlAttribute.vala
index b58474e..fdd6353 100644
--- a/gxml/GXmlAttribute.vala
+++ b/gxml/GXmlAttribute.vala
@@ -30,7 +30,6 @@ public class GXml.GAttribute : GXml.GNode, GXml.Attribute
   public GAttribute (GDocument doc, Xml.Attr *node)
   {
     _attr = node;
-    Test.message ("Attr Name: "+node->name);
     _node = _attr->parent;
     _doc = doc;
   }
@@ -46,7 +45,6 @@ public class GXml.GAttribute : GXml.GNode, GXml.Attribute
     owned get {
       if (_attr == null) return null;
       if (_attr->ns == null) return null;
-      Test.message ("Attr Namespace: "+_attr->name+" : "+_attr->ns->prefix);
       return new GNamespace (_attr->ns);
     }
     set {
diff --git a/gxml/GXmlElement.vala b/gxml/GXmlElement.vala
index b5baf5d..698f7a0 100644
--- a/gxml/GXmlElement.vala
+++ b/gxml/GXmlElement.vala
@@ -53,14 +53,12 @@ public class GXml.GElement : GXml.GNode, GXml.Element
     if (":" in name) {
       string[] pp = name.split (":");
       if (pp.length != 2) return null;
-      Test.message ("Checking for namespaced attribute: "+name);
       prefix = pp[0];
       n = pp[1];
     }
     var ps = _node->properties;
     Test.message ("Name= "+n+" Prefix= "+prefix);
     while (ps != null) {
-      Test.message ("At Attribute: "+ps->name);
       if (ps->name == n) {
         if (ps->ns == null && prefix == "") return new GAttribute (_doc, ps);
         if (ps->ns == null) continue;
diff --git a/gxml/GXmlHashMapAttr.vala b/gxml/GXmlHashMapAttr.vala
index d0a2cfa..f51891e 100644
--- a/gxml/GXmlHashMapAttr.vala
+++ b/gxml/GXmlHashMapAttr.vala
@@ -61,11 +61,9 @@ public class GXml.GHashMapAttr : Gee.AbstractMap<string,GXml.Node>
     if (":" in key) {
       string[] pp = key.split (":");
       if (pp.length != 2) return null;
-      Test.message ("Checking for namespaced attribute: "+key);
       var ps = _node->properties;
       var prefix = pp[0];
       var n = pp[1];
-      Test.message ("Name= "+n+" Prefix= "+prefix);
       while (ps != null) {
         Test.message ("At Attribute: "+ps->name);
         if (ps->name == n) {
diff --git a/gxml/SerializableProperty.vala b/gxml/SerializableProperty.vala
index 94941dc..bda8eb9 100644
--- a/gxml/SerializableProperty.vala
+++ b/gxml/SerializableProperty.vala
@@ -81,14 +81,12 @@ public interface GXml.SerializableProperty : Object
   {
     if (get_serializable_property_value () == null) return element;
     string name = "";
-    Test.message ("Use nick: "+nick.to_string ());
     if (nick &&
         prop.get_nick () != null &&
         prop.get_nick () != "")
       name = prop.get_nick ();
     else
       name = prop.get_name ();
-    Test.message ("Property to set:"+name+" - with value: "+get_serializable_property_value ());
     if (!(element is GXml.Element)) {
       GLib.warning (_("Trying to serialize to a non GXmlElement!"));
       return element;
@@ -128,4 +126,4 @@ public interface GXml.SerializableProperty : Object
       set_serializable_property_value (attr.value);
     return true;
   }
-}
\ No newline at end of file
+}
diff --git a/gxml/TwDocument.vala b/gxml/TwDocument.vala
index 6ab64bd..5d40bbf 100644
--- a/gxml/TwDocument.vala
+++ b/gxml/TwDocument.vala
@@ -151,15 +151,10 @@ public class GXml.TwDocument : GXml.TwNode, GXml.Document
   {
     var buf = new Xml.Buffer ();
     var tw = Xmlx.new_text_writer_memory (buf, 0);
-    GLib.Test.message ("Writing down to buffer");
     write_document (doc, tw);
-    GLib.Test.message ("Writing down to file");
-    GLib.Test.message ("TextWriter buffer:\n"+buf.content ());
     var s = new GLib.StringBuilder ();
     s.append (buf.content ());
-    GLib.Test.message ("Writing down to file: Creating input stream");
     var b = new GLib.MemoryInputStream.from_data (s.data, null);
-    GLib.Test.message ("Writing down to file: Replacing with backup");
     var ostream = f.replace (null, doc.backup, GLib.FileCreateFlags.NONE, cancellable);
     ostream.splice (b, GLib.OutputStreamSpliceFlags.NONE);
     ostream.close ();
diff --git a/gxml/libxml-Element.vala b/gxml/libxml-Element.vala
index 48fb1b7..0166779 100644
--- a/gxml/libxml-Element.vala
+++ b/gxml/libxml-Element.vala
@@ -95,7 +95,6 @@ namespace GXml {
                                if (this._attributes == null) {
                                        this._attributes = new NamedAttrMap (this);
                                }
-                               Test.message ("Getting Attributes NamedAttrMap");
                                return (NamedAttrMap) this._attributes;
                        }
                        internal set {
diff --git a/gxml/libxml-NamedAttrMap.vala b/gxml/libxml-NamedAttrMap.vala
index 04a418a..d583437 100644
--- a/gxml/libxml-NamedAttrMap.vala
+++ b/gxml/libxml-NamedAttrMap.vala
@@ -149,10 +149,8 @@ namespace GXml {
                        requires (elem != null)
                        requires (elem.node != null)
                {
-                       Test.message ("Getting from libxml2 an attribute node");
                        var at = elem.node->has_prop (key);
                        if (at == null) return null;
-                       Test.message ("Creating attribute with libxml2 node");
                        return (Attribute) new xAttr(at, (xDocument) elem.document);
                }
                public bool has (string key, Attribute value)
diff --git a/test/gxml-performance.vala b/test/gxml-performance.vala
index f17250b..9757974 100644
--- a/test/gxml-performance.vala
+++ b/test/gxml-performance.vala
@@ -131,7 +131,7 @@ public class Performance
       GLib.message ("Node: "+name+" Val: "+val+ " Children: "+i.to_string ());
 #endif
       if (i > 0)
-        Performance.iterate (n);
+        Performance.iterate (n);  
     }
   }
   public static void add_tests ()
@@ -174,7 +174,7 @@ public class Performance
         assert_not_reached ();
       }
     });
-    Test.add_func ("/gxml/performance/deserialize", 
+    Test.add_func ("/gxml/performance/deserialize/xdocument", 
     () => {
       try {
         double time;
@@ -195,7 +195,7 @@ public class Performance
       }
     });
 
-    Test.add_func ("/gxml/performance/serialize",
+    Test.add_func ("/gxml/performance/serialize/xdocument",
     () => {
       try {
         double time;
@@ -220,12 +220,58 @@ public class Performance
         assert_not_reached ();
       }
     });
-    Test.add_func ("/gxml/performance/tw-serialize",
+    Test.add_func ("/gxml/performance/deserialize/gdocument", 
     () => {
       try {
         double time;
         Test.timer_start ();
-        var d = new xDocument.from_path (GXmlTest.get_test_dir () + "/test-large.xml");
+        var d = new GDocument.from_path (GXmlTest.get_test_dir () + "/test-large.xml");
+        time = Test.timer_elapsed ();
+        Test.minimized_result (time, "open document from path: %g seconds", time);
+        Test.timer_start ();
+        var bs = new BookStore ();
+        bs.deserialize (d);
+        time = Test.timer_elapsed ();
+        Test.minimized_result (time, "deserialize/performance: %g seconds", time);
+      } catch (GLib.Error e) {
+#if DEBUG
+        GLib.message ("ERROR: "+e.message);
+#endif
+        assert_not_reached ();
+      }
+    });
+
+    Test.add_func ("/gxml/performance/serialize/gdocument",
+    () => {
+      try {
+        double time;
+        Test.timer_start ();
+        var d = new GDocument.from_path (GXmlTest.get_test_dir () + "/test-large.xml");
+        time = Test.timer_elapsed ();
+        Test.minimized_result (time, "open document from path: %g seconds", time);
+        Test.timer_start ();
+        var bs = new BookStore ();
+        bs.deserialize (d);
+        time = Test.timer_elapsed ();
+        Test.minimized_result (time, "deserialize/performance: %g seconds", time);
+        Test.timer_start ();
+        var d2 = new xDocument ();
+        bs.serialize (d2);
+        time = Test.timer_elapsed ();
+        Test.minimized_result (time, "serialize/performance: %g seconds", time);
+      } catch (GLib.Error e) {
+#if DEBUG
+        GLib.message ("ERROR: "+e.message);
+#endif
+        assert_not_reached ();
+      }
+    });
+    Test.add_func ("/gxml/performance/serialize/tw-document",
+    () => {
+      try {
+        double time;
+        Test.timer_start ();
+        var d = new GDocument.from_path (GXmlTest.get_test_dir () + "/test-large.xml");
         time = Test.timer_elapsed ();
         Test.minimized_result (time, "open document from path: %g seconds", time);
         Test.timer_start ();
@@ -233,22 +279,6 @@ public class Performance
         bs.deserialize (d);
         time = Test.timer_elapsed ();
         Test.minimized_result (time, "standard deserialize/performance: %g seconds", time);
-        assert (bs.name == "The Great Book");
-        assert (bs.books.size > 10);
-        var b = bs.books.first ();
-        assert (b != null);
-        assert (b.name != null);
-        assert (b.name.get_name () == "Book1");
-        assert (b.year == "2015");
-        assert (b.authors != null);
-        assert (b.authors.array != null);
-        assert (b.authors.array.size == 2);
-        var a = b.authors.array.first ();
-        assert (a != null);
-        assert (a.name != null);
-        assert (a.name.get_name () == "Fred");
-        assert (a.email != null);
-        assert (a.email.get_mail () == "fweasley hogwarts co uk");
         Test.timer_start ();
         var d2 = new TwDocument.for_path (GXmlTest.get_test_dir () + "/test-large.xml");
         bs.serialize (d2);


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