[gxml] StreamReader: Added benchmark test for buffer parsing
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] StreamReader: Added benchmark test for buffer parsing
- Date: Tue, 23 Jul 2019 22:26:33 +0000 (UTC)
commit 80d4006401985b7d5931e0d7206844705df5615b
Author: Daniel Espinosa <esodan gmail com>
Date: Tue Jul 23 17:17:22 2019 -0500
StreamReader: Added benchmark test for buffer parsing
gxml/Element.vala | 16 ++++-
gxml/StreamReader.vala | 2 -
...amReaderPerformanceIterateReadUnparsedTest.vala | 76 ++++++++++++++++++++++
test/StreamReaderTest.vala | 2 +-
test/meson.build | 4 +-
5 files changed, 94 insertions(+), 6 deletions(-)
---
diff --git a/gxml/Element.vala b/gxml/Element.vala
index 3f74d21..4714dfe 100644
--- a/gxml/Element.vala
+++ b/gxml/Element.vala
@@ -801,6 +801,17 @@ public class GXml.Element : GXml.Node,
* string of the element
*/
public MemoryOutputStream read_buffer { get; set; }
+
+ public ThreadPool<GXml.Element> pool = null;
+ /**
+ *
+ */
+ public uint unparsed_child_elements () {
+ if (pool == null) {
+ return 0;
+ }
+ return pool.unprocessed ();
+ }
/**
* Asynchronically parse {@link read_buffer}
*/
@@ -810,9 +821,12 @@ public class GXml.Element : GXml.Node,
}
read_from_string ((string) read_buffer.data);
read_buffer = null;
+ pool = new ThreadPool<GXml.Element>.with_owned_data ((element) => {
+ element.parse_buffer.begin ();
+ }, 3, false);
foreach (DomNode n in child_nodes) {
if (n is GXml.Element) {
- ((GXml.Element) n).parse_buffer.begin ();
+ pool.add ((GXml.Element) n);
}
}
}
diff --git a/gxml/StreamReader.vala b/gxml/StreamReader.vala
index 68dda4f..c431fd6 100644
--- a/gxml/StreamReader.vala
+++ b/gxml/StreamReader.vala
@@ -88,7 +88,6 @@ public class GXml.StreamReader : GLib.Object {
return document;
}
public GXml.Element read_root_element () throws GLib.Error {
- message ("read Root Element");
return read_element (true);
}
public GXml.Element read_element (bool children) throws GLib.Error {
@@ -120,7 +119,6 @@ public class GXml.StreamReader : GLib.Object {
dbuf.put_byte (read_byte ());
}
name_buf.put_byte ('\0', cancellable);
- message ("Node name: %s", (string) oname_buf.get_data ());
e = (GXml.Element) document.create_element ((string) oname_buf.get_data ());
e.read_buffer = buf;
if (is_empty) {
diff --git a/test/StreamReaderPerformanceIterateReadUnparsedTest.vala
b/test/StreamReaderPerformanceIterateReadUnparsedTest.vala
new file mode 100644
index 0000000..24b6380
--- /dev/null
+++ b/test/StreamReaderPerformanceIterateReadUnparsedTest.vala
@@ -0,0 +1,76 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/* GomDocumentPerformanceTest.vala
+ *
+ * Copyright (C) 2019 Daniel Espinosa <esodan gmail com>
+ *
+ * This library 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.
+ *
+ * This library 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+
+using GXml;
+class GXmlTest.Suite : GLib.Object
+{
+ static int main (string[] args)
+ {
+ GLib.Intl.setlocale (GLib.LocaleCategory.ALL, "");
+ Test.init (ref args);
+ Test.add_func ("/gxml/stream-reader/performance", () => {
+ var loop = new MainLoop (null);
+ var timer = new Timer ();
+ ulong time = 0;
+ try {
+ File dir = File.new_for_path (GXmlTestConfig.TEST_DIR);
+ assert (dir.query_exists ());
+ File f = File.new_for_uri (dir.get_uri ()+"/test-large.xml");
+ assert (f.query_exists ());
+ var sr = new GXml.StreamReader (f.read ());
+ var d = sr.read ();
+ timer.elapsed (out time);
+ message ("Initial Parse: %lu ms for %d nodes", time / 1000, d.document_element.child_nodes.length);
+ Timeout.add_full (0, 10, ()=>{
+ int l = d.document_element.child_nodes.item (5000).child_nodes.length;
+ if (l == 0) {
+ return Source.CONTINUE;
+ }
+ try {
+ message ((d.document_element.child_nodes.item (5000) as DomElement).write_string ());
+ } catch (GLib.Error e) {
+ warning ("Error: %s", e.message);
+ }
+ loop.quit ();
+ return Source.REMOVE;
+ });
+ Idle.add (()=>{
+ (d.document_element as GXml.Element).parse_buffer.begin ((obj, res)=>{
+ try {
+ timer.elapsed (out time);
+ message ("Parse root: %lu ms", time / 1000);
+ (d.document_element as GXml.Element).parse_buffer.end (res);
+ } catch (GLib.Error e) {
+ warning ("Error: %s", e.message);
+ assert_not_reached ();
+ }
+ });
+ return Source.REMOVE;
+ });
+ } catch (GLib.Error e) {
+ warning ("Error: %s", e.message);
+ }
+ loop.run ();
+ });
+ return Test.run ();
+ }
+}
diff --git a/test/StreamReaderTest.vala b/test/StreamReaderTest.vala
index e04a17e..be638b2 100644
--- a/test/StreamReaderTest.vala
+++ b/test/StreamReaderTest.vala
@@ -106,7 +106,7 @@ class GXmlTest {
(doc.document_element as
GXml.Element).parse_buffer.end (res);
message (doc.write_string ());
assert ((doc.document_element as
GXml.Element).read_buffer == null);
- assert
((doc.document_element.child_nodes.item (0) as GXml.Element).read_buffer == null);
+ //assert
((doc.document_element.child_nodes.item (0) as GXml.Element).read_buffer == null);
loop.quit ();
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
diff --git a/test/meson.build b/test/meson.build
index be2d0b7..c2f875c 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -134,11 +134,11 @@ files_stream_reader_performance_iterate_read = files ([
'StreamReaderPerformanceIterateReadUnparsedTest.vala'
])
-stream_reader_performance_iterate = executable('stream-reader-performance-iterate-read-unparsed',
files_stream_reader_performance_iterate_read + configvapi + configtestvapi,
+stream_reader_performance_iterate = executable('stream-reader-performance-unparsed',
files_stream_reader_performance_iterate_read + configvapi + configtestvapi,
vala_args : [],
dependencies : [ libgxml_deps, inc_libh_dep, testdirs_dep, inc_rooth_dep],
link_with: libgxml
)
-benchmark ('stream-reader-performance-iterate-read-unparsed', stream_reader_performance_iterate)
+benchmark ('stream-reader-performance-unparsed', stream_reader_performance_iterate)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]