Last active
January 4, 2016 07:59
-
-
Save palexander/8592640 to your computer and use it in GitHub Desktop.
Revisions
-
palexander revised this gist
Jan 24, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -33,3 +33,7 @@ def set_with_keywords(name: "default name", email: "[email protected]") end end end user system total real hash: 8.130000 0.290000 8.420000 ( 8.420061) keywords: 13.720000 0.540000 14.260000 ( 14.275596) -
palexander created this gist
Jan 24, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ require 'benchmark' COUNT = 10_000_000 NAME = "Test Name" EMAIL = "[email protected]" class Person attr_accessor :name, :email def set_with_hash(options = {}) @name = options[:name] || "default name" @email = options[:email] || "[email protected]" end def set_with_keywords(name: "default name", email: "[email protected]") @name = name @email = email end end Benchmark.bm(10) do |x| x.report("hash:") do COUNT.times do p = Person.new p.set_with_hash(name: NAME, email: EMAIL) end end x.report("keywords:") do COUNT.times do p = Person.new p.set_with_keywords(name: NAME, email: EMAIL) end end end