It orders floats, which slows down.
require 'benchmark' class ToBeMarshaled def initialize n @a = [] n.times do |i| @a << i.to_f end end end tbm = ToBeMarshaled.new(10000) n = 100 Benchmark.bm do |x| x.report("Marshal Dump") {for i in 1..n; Marshal.dump(tbm); end} end
(ran the test 3 times for each version of Ruby):
2.1.5 user system total real Marshal Dump 0.640000 0.010000 0.650000 ( 0.744080) Marshal Dump 0.670000 0.000000 0.670000 ( 0.758597) Marshal Dump 0.650000 0.020000 0.670000 ( 0.747583) 2.2.0 user system total real Marshal Dump 25.070000 0.220000 25.290000 ( 27.980023) Marshal Dump 24.100000 0.160000 24.260000 ( 26.633049) Marshal Dump 24.440000 0.230000 24.670000 ( 27.540826)
~ 35 times slower.
If you take ".to_f" from this code, you get:
2.1.5 user system total real Marshal Dump 0.160000 0.000000 0.160000 ( 0.180247) Marshal Dump 0.180000 0.000000 0.180000 ( 0.189485) Marshal Dump 0.160000 0.010000 0.170000 ( 0.191304) 2.2.0 user system total real Marshal Dump 0.120000 0.010000 0.130000 ( 0.146710) Marshal Dump 0.130000 0.010000 0.140000 ( 0.159851) Marshal Dump 0.130000 0.000000 0.130000 ( 0.143917)
2.2.0 slightly ends with 2.1.5.
davej source share