This file contains 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' | |
class Obj | |
def with_condition | |
respond_to?(:mythical_method) ? self.mythical_method : nil | |
end | |
def with_rescue | |
self.mythical_method | |
rescue NoMethodError |
This file contains 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 = 1000 | |
BASIC_LENGTH = 10 | |
puts RUBY_DESCRIPTION | |
5.times do |factor| | |
length = BASIC_LENGTH * (10 ** factor) | |
puts "_" * 60 + "\nLENGTH: #{length}" |
This file contains 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' | |
def n_func(array) | |
array.inject({}) { |h, e| h[e] = e; h } | |
end | |
def n2_func(array) | |
array.inject({}) { |h, e| h.merge(e => e) } | |
end |
This file contains 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' | |
class Metric | |
attr_accessor :var | |
def initialize(n) | |
@n = n | |
@var = 22 | |
end |
This file contains 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 = 10_000_000 | |
puts RUBY_DESCRIPTION | |
Benchmark.bm(15) do |x| | |
x.report('parallel') do | |
N.times do | |
a, b = 10, 20 |
This file contains 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' | |
class Metric | |
N = 1_000_000 | |
def self.class_eval_with_string | |
N.times do |i| | |
class_eval(<<-eorb, __FILE__, __LINE__ + 1) | |
def smeth_#{i} | |
#{i} |
This file contains 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' | |
def merge!(array) | |
array.inject({}) { |h, e| h.merge!(e => e) } | |
end | |
def merge(array) | |
array.inject({}) { |h, e| h.merge(e => e) } | |
end |