Which is much faster XMLParser or SimpleXML

What do you guys think? I am currently using SimpleXML for my entire project, which has an average of 250 KB when using memory with 500 seconds per second to execute. I'm just planning on switching to XMLParser, your advice is greatly appreciated.

Edit: The actual firmware time is 0,000578 microseconds. Im just messed up in milli and micro, lol.

+4
source share
3 answers

In most cases, XML Parser will be much slower both in terms of development and execution, mainly because you need to write / execute tons of userland PHP code to navigate / read your document.

In some cases, you may find some improvement with XMLReader (not sure about XML Parser), but cost is extra development time and more complicated maintenance. Since the application already uses SimpleXML and uses only 250KB, your time will most likely be better spent on other areas of your application. 500 ms is enough for XML processing with SimpleXML, you should profile this topic and / or publish your most processor-intensive procedure in another issue for optimization.

+4
source

In theory, at least XMLParser (a SAX ) can be more efficient (in speed, but especially in memory) than SimpleXML (a DOM ), especially when working with larger documents (DOM implementations load the entire XML tree at that time how the SAX implementation allows the programmer to simply navigate through XML without having to store anything in memory, leaving completely to you what you want to keep in memory) - see comparing different DOMs with different implementations of the SAX analyzer.

I can say that because SAX traversal is programmatically more complicated than moving or querying the DOM, and using SAX poorly (or using SAX in situations where the DOM is best suited anyway, for example, if you loaded at the end of your SAX traversal itself over almost the entire tree in memory) can actually lead to lower performance than using the DOM API .. p>

+16
source

Yes, XML Parser (not to be confused with XMLParser ) is preferable if you have memory problems because it does not require the entire file to be preloaded and pre-processed before use. This is similar to fgets () or fread () compared to file_get_contents ()

+4
source

Source: https://habr.com/ru/post/1306426/


All Articles