Skip to content

Instantly share code, notes, and snippets.

@Hinidu
Last active October 5, 2017 18:35
Show Gist options
  • Save Hinidu/90b05c678d730994c3eebea445e44e47 to your computer and use it in GitHub Desktop.
Save Hinidu/90b05c678d730994c3eebea445e44e47 to your computer and use it in GitHub Desktop.
Settings:
duration: 1.0 s
## CacheBench
[20:23:21] 1/4: failed filename lookup
[20:23:30] 2/4: failed term lookup
[20:23:33] 3/4: successful filename lookup
[20:23:34] 4/4: successful term lookup
Finished in 14.44 seconds
## CacheBench
benchmark name iterations average time
failed filename lookup 100000000 0.08 µs/op
successful filename lookup 10000000 0.13 µs/op
failed term lookup 20000 90.67 µs/op
successful term lookup 10000 102.44 µs/op
defmodule CacheBench do
use Benchfella
@filename "/opt/app/my_beatiful_application/deps/certifi/priv/cacerts.pem"
setup_all do
cache = :ets.new(:set_public_cache, [:set, :public])
cacerts = :certifi.cacerts()
:ets.insert(cache, {@filename, :x})
:ets.insert(cache, {cacerts, :x})
{:ok, {cache, cacerts}}
end
bench "successful filename lookup" do
{cache, _cacerts} = bench_context
[{_, :x}] = :ets.lookup(cache, @filename)
end
bench "successful term lookup" do
{cache, cacerts} = bench_context
[{_, :x}] = :ets.lookup(cache, cacerts)
end
bench "failed filename lookup" do
{cache, _cacerts} = bench_context
[] = :ets.lookup(cache, <<?a, @filename>>)
end
bench "failed term lookup" do
{cache, cacerts} = bench_context
[] = :ets.lookup(cache, [?a | cacerts])
end
end
defmodule CertifiBench.Mixfile do
use Mix.Project
def project do
[
app: :certifi_bench,
version: "0.1.0",
elixir: "~> 1.5",
start_permanent: Mix.env == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:benchfella, "~> 0.3"},
{:certifi, "~> 2.0"},
]
end
end
%{"benchfella": {:hex, :benchfella, "0.3.5", "b2122c234117b3f91ed7b43b6e915e19e1ab216971154acd0a80ce0e9b8c05f5", [], [], "hexpm"},
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [], [], "hexpm"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment