Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
0 contributors

Users who have contributed to this file

23 lines (17 sloc) 286 Bytes
require 'benchmark/ips'
NUM = 1.12678.freeze
def fast
NUM.round(2).to_s
end
def avg
format('%.2f', NUM)
end
def slow
'%.2f' % NUM
end
Benchmark.ips do |x|
x.report('Float#round') { fast }
x.report('Kernel#format') { avg }
x.report('String#%') { slow }
x.compare!
end
You can’t perform that action at this time.