This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| |