Skip to content

Instantly share code, notes, and snippets.

@yakreved
Created September 4, 2014 03:22
Show Gist options
  • Save yakreved/7d6f77ee6cab77754779 to your computer and use it in GitHub Desktop.
Save yakreved/7d6f77ee6cab77754779 to your computer and use it in GitHub Desktop.
ruby serialization speed test
require 'ruby-prof'
require 'factory_girl'
require 'date'
include FactoryGirl
class User
def initialize
@name= "jkjkj"+Random.rand(200).to_s
@birth = Date.today - Random.rand(3)
@num = Random.rand(600)
end
def to_s
"<"+@name+ " " + @birth.to_s+ " " + @num.to_s+ ">"
end
end
list = []
1_000_000.times do
list.append(User.new)
end
#p list
RubyProf.start
f = File.open( 'peoples.sav', 'w' )
Marshal.dump(list, f )
f.close
myfriends = Marshal.load(File.open('peoples.sav' ))
result = RubyProf.stop
# Print a flat profile to text
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment