Skip to content

Instantly share code, notes, and snippets.


Tom Fakes tomfakes

  • Mystery Science
  • Kirkland, WA, USA
  • Twitter @craz8
View GitHub Profile
tomfakes / Pathname Join Benchmark
Last active Sep 12, 2019
Pathname.join (Rails.root.join) vs String Interpolation benchmark
View Pathname Join Benchmark
Warming up --------------------------------------
pathname join 5.643k i/100ms
string iterp. 252.100k i/100ms
Calculating -------------------------------------
pathname join 57.791k (± 4.4%) i/s - 293.436k in 5.086740s
string iterp. 3.994M (± 2.1%) i/s - 20.168M in 5.051901s
string iterp.: 3993877.9 i/s
pathname join: 57791.3 i/s - 69.11x slower
tomfakes / fizzbuzz.rb
Created Aug 28, 2019
Benchmark of different FizzBuzz implementations in Ruby
View fizzbuzz.rb
require "benchmark/ips"
def fizz_buzz_text(num)
result = ''
result += 'Fizz' if (num % 3).zero?
result += 'Buzz' if (num % 5).zero?
result.empty? ? num.to_s : result
tomfakes / gist:7dfb9cbd64d130aff54363146b3c50ad
Created Jun 24, 2019
Benchmark for Compact vs Nil check
View gist:7dfb9cbd64d130aff54363146b3c50ad
require "benchmark/ips"
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
# To reduce overhead, the number of iterations is passed in
# and the block must run the code the specific number of times.
# Used for when the workload is very small and any overhead
# introduces incorrectable errors."add-if-not-nil") do |times|