|
Ruby Object XML Serialization |
|
Author: Published: |
In an attempt to use a more portable Object serialization method than Marshal that performed as well or better, Ox was born. A Ruby implementation on top of Nokogiri was prohibitively slower than using the native Ruby Marshal module. Marshal has a number of problem though. The format changes from one Ruby version to the next and it is not portable between any other languages. It is a binary format that is difficult to read, debug, or edit. As a extension, Ox is able to dump and load a Ruby Object to and from XML faster than the native Ruby Marshal can. Ox also supports serialization of Exceptions better than Marshal. The performance tests that demonstrate this are in perf_obj.rb. The results of the tests are shown below. Object Load obj = Ox.load(xml, :mode => :object) # Ox obj = Marshal.load(mars) # Marshal Test results taken from perf_obj.rb in the Ox project on GitHub are: |
|
> perf_obj.rb -l Using file sample.xml. Parsing 1000 times with Ox took 0.665415 seconds. Marshalling 1000 times took 1.833594 seconds. >>> Ox is 2.8 faster than Marshal loading. |
Load Results ![]() |
Object Dump xml = Ox.dump(obj, :indent => 2, :circular => $circular) # Ox mars = Marshal.dump(obj) # Marshal Test results taken from perf_obj.rb in the Ox project on GitHub are: |
|
> perf_obj.rb -d Using file sample.xml. Ox dumping 1000 times with ox took 0.341084 seconds. Marshal dumping 1000 times took 1.654322 seconds. >>> Ox is 4.9 faster than Marshal dumping. |
Dump Results ![]() |
Summary Using Ox for Object serialization and deserialization is much faster than Marshal in addition to being based on a more stable and readable format. Serializing, or dumping Objects with Ox was much faster than Marshal making Ox a good candidate for server side operations where loading is heavier in favor of serialization of data before it is sent to clients. Note: Tests were run on an 2.8 GHz iMac with a Core i7 CPU and Mac OS X 10.6.8. |
|
|