Created
October 22, 2025 09:25
-
-
Save katafrakt/d02158e1ff439effdad98452b315f23c to your computer and use it in GitHub Desktop.
Revisions
-
katafrakt created this gist
Oct 22, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ Mix.install([:benchee]) defmodule Lookup do @lookup_table %{ "one" => :one, "two" => :two, "three" => :three } def by_table(value) do Map.get(@lookup_table, value, :more) end def by_function(value) do case value do "one" -> :one "two" -> :two "three" -> :three _ -> :more end end end Benchee.run( %{ "by_table, found value" => fn -> Lookup.by_table("three") end, "by_table, fallback" => fn -> Lookup.by_table("five") end, "by_function, found value" => fn -> Lookup.by_function("three") end, "by_function, fallback" => fn -> Lookup.by_function("five") end } )