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 | |
Comparison: | |
string iterp.: 3993877.9 i/s | |
pathname join: 57791.3 i/s - 69.11x slower |
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 | |
end |
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. | |
x.report("add-if-not-nil") do |times| |