Why is binary serialization faster than xml serialization?

Consider serializing double for example:

  • binary serialization: writing 8 bytes from memory address to the stream

  • binary deserialization: reading same 8 bytes

  • xml serialization: writing tag, converting to text, writing closing tag - nearly thrice the I/O and 1000x more CPU utilization

  • xml deserialization: tag reading/validation, reading string parsing it to number, reading/validation of closing tag. little more overhead for I/O and some more for CPU


Binary serialization is more efficient because write raw data directly and the XML needs format, and parse the data to generate a valid XML structure, additionally depending of what sort of data have your objects the XML may have a lot of redundant data.