Last active
October 21, 2021 13:14
-
-
Save damonvjanis/59f2e5ed3f2e97c2b9e59da85297b3db to your computer and use it in GitHub Desktop.
Profiles a function that throws vs one that returns
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
Mix.install([:benchee]) | |
defmodule Profile do | |
def function_that_throws(input) do | |
throw(input) | |
catch | |
value -> value | |
end | |
def function_that_returns(input) do | |
input | |
end | |
end | |
Benchee.run( | |
%{ | |
"throw" => fn -> Profile.function_that_throws(:test) end, | |
"return" => fn -> Profile.function_that_returns(:test) end | |
}, | |
time: 10, | |
memory_time: 2 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment