Created
September 26, 2015 20:28
-
-
Save jamis/0b9e932a23f8b273a327 to your computer and use it in GitHub Desktop.
Compare Array#dup on 1D array, versus Marshal.load(Marshal.dump(...)) on 2D array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
N = 100_000 | |
SIZE = 10 | |
array_1d = Array.new(SIZE * SIZE, 0) | |
array_2d = Array.new(SIZE) { Array.new(SIZE, 0) } | |
Benchmark.bm do |bm| | |
bm.report("1d.dup") { N.times { array_1d.dup } } | |
bm.report("2d.dup") { N.times { Marshal.load(Marshal.dump(array_2d)) } } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user system total real | |
1d.dup 0.030000 0.000000 0.030000 ( 0.029078) | |
2d.dup 2.540000 0.010000 2.550000 ( 2.554168) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment