-
-
Save DangerDawson/9488598302a6d2ff9f2ea45912e5d4d7 to your computer and use it in GitHub Desktop.
Catch / Raise / Rescue / Throw benchmark
This file contains 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
# frozen_string_literal: true | |
require 'benchmark' | |
Benchmark.bmbm do |x| | |
x.report('Catch/Throw') do | |
1_000_000.times do | |
catch(:benchmarking) do | |
throw(:benchmarking) | |
end | |
end | |
end | |
x.report('Raise/Rescue') do | |
1_000_000.times do | |
raise | |
rescue StandardError | |
# Do nothing | |
end | |
end | |
x.report('Throw/Rescue') do | |
1_000_000.times do | |
throw(:benchmarking) | |
rescue StandardError | |
# Do nothing | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment