Skip to content

Instantly share code, notes, and snippets.

@DangerDawson
Created July 14, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DangerDawson/9488598302a6d2ff9f2ea45912e5d4d7 to your computer and use it in GitHub Desktop.
Save DangerDawson/9488598302a6d2ff9f2ea45912e5d4d7 to your computer and use it in GitHub Desktop.
Catch / Raise / Rescue / Throw benchmark
# 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