Skip to content

Instantly share code, notes, and snippets.

@Hettomei
Created February 26, 2015 13:25
Show Gist options
  • Save Hettomei/99c4b53ee3936d9acaca to your computer and use it in GitHub Desktop.
Save Hettomei/99c4b53ee3936d9acaca to your computer and use it in GitHub Desktop.
Benchmark procedural vs splité en methode
#Rehearsal ---------------------------------------
#old 3.360000 0.000000 3.360000 ( 3.364614)
#new 4.790000 0.000000 4.790000 ( 4.787060)
#------------------------------ total: 8.150000sec
#
# user system total real
#old 3.380000 0.000000 3.380000 ( 3.376807)
#new 4.680000 0.000000 4.680000 ( 4.677751)
require 'benchmark'
iteration = 5000000
class ToutALaSuite
def init
@a = "bonjour"
@a.capitalize!
@a.chomp!
@a.chop!
@a.downcase!
@a.lstrip!
@a.next!
@a.reverse!
@a.strip!
end
end
class DecoupeEnMethode
def init
@a = "bonjour"
a
b
c
d
e
f
g
h
end
def a
@a.capitalize!
end
def b
@a.chomp!
end
def c
@a.chop!
end
def d
@a.downcase!
end
def e
@a.lstrip!
end
def f
@a.next!
end
def g
@a.reverse!
end
def h
@a.strip!
end
end
Benchmark.bmbm do |performance|
performance.report("old") do
iteration.times do
ToutALaSuite.new.init
end
end
performance.report("new") do
iteration.times do
DecoupeEnMethode.new.init
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment