Skip to content

Instantly share code, notes, and snippets.

@spangenberg
Last active December 19, 2015 15:09
Show Gist options
  • Select an option

  • Save spangenberg/5974704 to your computer and use it in GitHub Desktop.

Select an option

Save spangenberg/5974704 to your computer and use it in GitHub Desktop.
require 'benchmark'
texts, marshaled_texts = [], []
n = 1_000_000
puts "Write:"
Benchmark.bm(17) do |x|
x.report('without marshal:') { for i in 1..n; texts << (0...8).map{(65+rand(26)).chr}.join end }
x.report('with marshal:') { for i in 1..n; marshaled_texts << Marshal.dump((0...8).map{(65+rand(26)).chr}.join) end }
end
puts "\nRead:"
Benchmark.bm(17) do |x|
x.report('without marshal:') { for i in 1..n; texts.pop end }
x.report('with marshal:') { for i in 1..n; Marshal.load(marshaled_texts.pop) end }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment