Skip to content

Instantly share code, notes, and snippets.

View szajbus's full-sized avatar
👋

Michał Szajbe szajbus

👋
View GitHub Profile
#!/usr/bin/ruby
require 'benchmark'
include Benchmark
pi = 3.14
n = 1000000
Benchmark.benchmark(" "*7 + CAPTION, 7, FMTSTR) do |x|
to_i = x.report("to_i:") { n.times { pi != pi.to_i } }
gsub = x.report("gsub:") { n.times { pi.to_s.gsub(/^.*\.(.*)$/, '\1').to_i > 0 } }