Add various benchmarks regarding URI creation

This commit is contained in:
Marcel Otto 2017-08-19 22:56:17 +02:00
parent 82662ab19d
commit ec67c2379f
4 changed files with 98 additions and 3 deletions

90
bench/uris.exs Normal file
View file

@ -0,0 +1,90 @@
hash = %{"http://example.com/foo/bar" => RDF.uri("http://example.com/foo/bar")}
Benchee.run(%{
"URI.parse" => fn ->
RDF.uri("http://example.com/foo/bar")
end,
"RDF.IRI.new" => fn ->
RDF.IRI.new("http://example.com/foo/bar")
end,
"RDF.IRI.new!" => fn ->
RDF.IRI.new!("http://example.com/foo/bar")
end,
"hash lookup" => fn ->
hash["http://example.com/foo/bar"]
end,
})
Benchee.run(%{
"bare uri" => fn ->
RDF.uri("http://example.com/foo/bar")
end,
"bare triple" => fn ->
RDF.triple({RDF.uri("http://example.com/foo/bar"),
RDF.uri("http://example.com/foo/baz"),
RDF.uri("http://example.com/foo/quux")
})
end,
"Graph with triple" => fn ->
RDF.Graph.new(
RDF.triple({RDF.uri("http://example.com/foo/bar"),
RDF.uri("http://example.com/foo/baz"),
RDF.uri("http://example.com/foo/quux")
})
)
end,
})
Benchee.run(%{
"1_000_000 bare uris" => fn ->
for i <- 1..1_000_000 do
RDF.uri("http://example.com/foo/bar#{i}")
end
end,
"1_000_000 bare triples" => fn ->
for i <- 1..1_000_000 do
RDF.triple({RDF.uri("http://example.com/foo/bar#{i}"),
RDF.uri("http://example.com/foo/baz#{i}"),
RDF.uri("http://example.com/foo/quux#{i}")
})
end
end,
"Graph with 1_000_000 triples" => fn ->
Enum.reduce 1..1_000_000, RDF.Graph.new(), fn i, graph ->
RDF.Graph.add graph,
RDF.triple({RDF.uri("http://example.com/foo/bar#{i}"),
RDF.uri("http://example.com/foo/baz#{i}"),
RDF.uri("http://example.com/foo/quux#{i}")
})
end
end,
})
IO.puts "\n\nErlang Term Info (Memory Consumption)"
uris =
for i <- 1..1_000_000 do
RDF.uri("http://example.com/foo/bar#{i}")
end
IO.puts "1_000_000 bare uris: #{:erlang_term.byte_size(uris)}"
triples =
for i <- 1..1_000_000 do
RDF.triple({RDF.uri("http://example.com/foo/bar#{i}"),
RDF.uri("http://example.com/foo/baz#{i}"),
RDF.uri("http://example.com/foo/quux#{i}")
})
end
IO.puts "1_000_000 bare triples: #{:erlang_term.byte_size(triples)}"
graph =
Enum.reduce 1..1_000_000, RDF.Graph.new(), fn i, graph ->
RDF.Graph.add graph,
RDF.triple({RDF.uri("http://example.com/foo/bar#{i}"),
RDF.uri("http://example.com/foo/baz#{i}"),
RDF.uri("http://example.com/foo/quux#{i}")
})
end
IO.puts "Graph with 1_000_000 triples: #{:erlang_term.byte_size(graph)}"

View file

@ -1,5 +1,5 @@
use Mix.Config
unless Mix.env == :docs do
unless Mix.env in ~w[docs bench]a do
import_config "#{Mix.env}.exs"
end

View file

@ -64,7 +64,9 @@ defmodule RDF.Mixfile do
{:ex_doc, "~> 0.14", only: :dev, runtime: false},
{:mix_test_watch, "~> 0.3", only: :dev, runtime: false},
{:excoveralls, "~> 0.7", only: :test},
{:inch_ex, only: :docs},
{:inch_ex, "~> 0.5", only: [:dev, :test]},
{:benchee, "~> 0.9", only: :bench},
{:erlang_term, "~> 1.7", only: :bench},
]
end
end

View file

@ -1,8 +1,11 @@
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
%{"benchee": {:hex, :benchee, "0.9.0", "433d946b0e4755e186fe564568ead4f593b0d15337fcffa95ed7d5b8a6612670", [:mix], [{:deep_merge, "~> 0.1", [hex: :deep_merge, optional: false]}]},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], []},
"credo": {:hex, :credo, "0.8.1", "137efcc99b4bc507c958ba9b5dff70149e971250813cbe7d4537ec7e36997402", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
"deep_merge": {:hex, :deep_merge, "0.1.1", "c27866a7524a337b6a039eeb8dd4f17d458fd40fbbcb8c54661b71a22fffe846", [:mix], []},
"dialyxir": {:hex, :dialyxir, "0.5.0", "5bc543f9c28ecd51b99cc1a685a3c2a1a93216990347f259406a910cf048d1d7", [:mix], []},
"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], []},
"erlang_term": {:hex, :erlang_term, "1.7.1", "f83d470b27e1fabdbd19fb91489d3394a05813ea69643ad4354572700d715aac", [:rebar3], []},
"ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.7.2", "f69ede8c122ccd3b60afc775348a53fc8c39fe4278aee2f538f0d81cc5e7ff3a", [:mix], [{:exjsx, ">= 3.0.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},