Skip to content

Instantly share code, notes, and snippets.

@eebs
Last active October 21, 2019 20:24
Show Gist options
  • Save eebs/2bf0355a10a629a38a80e3b8735e8fa1 to your computer and use it in GitHub Desktop.
Save eebs/2bf0355a10a629a38a80e3b8735e8fa1 to your computer and use it in GitHub Desktop.
Truthy Benchmark
require "rspec"
require "rspec/autorun"
require 'benchmark'
n = 1_000
Benchmark.bmbm(7) do |x|
x.report("eq:") do
RSpec.describe "eq" do
n.times do
it "tests equality" do
expect(true).to eq(true)
end
end
end
end
x.report("truthy:") do
RSpec.describe "truthy" do
n.times do
it "tests equality" do
expect(true).to be_truthy
end
end
end
end
end
❯ ruby truthy.rb
Rehearsal -------------------------------------------
eq: 0.070174 0.029242 0.099416 ( 0.099766)
truthy: 0.032358 0.020314 0.052672 ( 0.052903)
---------------------------------- total: 0.152088sec
user system total real
eq: 0.033629 0.022308 0.055937 ( 0.056277)
truthy: 0.035485 0.022177 0.057662 ( 0.057886)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment