Example: /XML/XML Benchmark

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/XML/XML Benchmark


Required plugins for this example: MBS XML Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /XML/XML Benchmark

This example is the version from Wed, 23th Aug 2022.

Project "XML Benchmark.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits DesktopWindow
Control List Inherits DesktopListBox
ControlInstance List Inherits DesktopListBox
End Control
EventHandler Sub Opening() Dim file As FolderItem = SpecialFolder.Desktop.Child("test.xml") If Not file.Exists Then MessageBox "Please put test.xml on the desktop." Return End If Dim Bin As BinaryStream = BinaryStream.Open(file) Dim data As String = Bin.Read(Bin.Length, encodings.UTF8) list.AddRow "Size of XML file: " + data.Bytes.ToString Dim t1 As Double = Microseconds Dim xdoc As New XmlDocument(data) Dim t2 As Double = Microseconds Dim mdoc As New XMLDocumentMBS(data) Dim t3 As Double = Microseconds list.AddRow "XmlDocument parse: " + Str( (t2-t1) / 1000.0, "0.0") + " ms" list.AddRow "XMLDocumentMBS parse: " + Str( (t3-t2) / 1000.0, "0.0") + " ms" Dim xnodes() As XmlNode Dim mnodes() As XMLElementMBS t1 = Microseconds FindNodes mdoc, "exports", mnodes t2 = Microseconds FindNodes xdoc, "exports", xnodes t3 = Microseconds list.AddRow "FindNodes MBS: " + Str( (t2-t1) / 1000.0, "0.0") + " ms for "+mnodes.Count.toString+" elements" list.AddRow "FindNodes Xojo: " + Str( (t3-t2) / 1000.0, "0.0") + " ms for "+xnodes.Count.toString+" elements" Redim xnodes(-1) Redim mnodes(-1) // second run with some caching t1 = Microseconds FindNodes mdoc, "exports", mnodes t2 = Microseconds FindNodes xdoc, "exports", xnodes t3 = Microseconds list.AddRow "FindNodes MBS: " + Str( (t2-t1) / 1000.0, "0.0") + " ms for "+mnodes.Count.toString+" elements" list.AddRow "FindNodes Xojo: " + Str( (t3-t2) / 1000.0, "0.0") + " ms for "+xnodes.Count.toString+" elements" Redim xnodes(-1) Redim mnodes(-1) t1 = Microseconds mnodes = mdoc.ElementsByTagName("exports") t2 = Microseconds list.AddRow "ElementsByTagName MBS: " + Str( (t2-t1) / 1000.0, "0.0") + " ms for "+mnodes.Count.toString+" elements" Redim xnodes(-1) Redim mnodes(-1) t1 = Microseconds Dim nodes() As XMLNodeMBS Dim WhatToShow As Integer = mdoc.ShowElement Dim walker As XMLNodeIteratorMBS = mdoc.createNodeIterator(Nil, WhatToShow) Dim node As XmlNodeMBS = walker.Current While node <> Nil If node.LocalName = "exports" Then nodes.Add node End If node = walker.nextNode Wend t2 = Microseconds list.AddRow "XMLNodeIteratorMBS: " + Str( (t2-t1) / 1000.0, "0.0") + " ms for "+nodes.Count.toString+" elements" End EventHandler
Sub FindNodes(element as XMLElementMBS, NodeName as string, nodes() as XmlElementMBS) #Pragma DisableBackgroundTasks While element <> Nil // match this If element.LocalName = NodeName Then nodes.Add element End If // recursion to look into sub elements Dim c As XmlElementMBS = element.FirstElementChild If c <> Nil Then FindNodes c, NodeName, nodes End If element = element.NextElementSibling Wend End Sub
Sub FindNodes(doc as XmlDocument, NodeName as string, nodes() as XmlElement) #Pragma DisableBackgroundTasks FindNodes doc.FirstChild, NodeName, nodes End Sub
Sub FindNodes(doc as XmlDocumentMBS, NodeName as string, nodes() as XmlElementMBS) #Pragma DisableBackgroundTasks Dim v As Variant = doc.FirstChild Dim n As XMLElementMBS = v FindNodes n, NodeName, nodes End Sub
Sub FindNodes(element as XmlNode, NodeName as string, nodes() as XmlNode) #Pragma DisableBackgroundTasks While element <> Nil // match this If element.LocalName = NodeName Then nodes.Add element End If // recursion to look into sub elements Dim c As XmlNode = element.FirstChild If c <> Nil Then FindNodes c, NodeName, nodes End If element = element.NextSibling Wend End Sub
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem HelpMenu = "&Help"
End MenuBar
End Project

See also:

The items on this page are in the following plugins: MBS XML Plugin.


💬 Ask a question or report a problem