Skip to content

Commit

Permalink
:benchee interface for calling benchee from Erlang
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Jun 4, 2017
1 parent b3ddbc1 commit 5ac381d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/benchee.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Idea from this:
# https://elixirforum.com/t/writing-a-library-for-use-in-both-elixir-and-erlang/2900/5?u=pragtob
defmodule Benchee.Impl do
@moduledoc false
defmacro __using__(_) do
quote do
@doc """
Expand Down Expand Up @@ -75,6 +76,15 @@ defmodule Benchee do
@moduledoc """
Top level module providing convenience access to needed functions as well
as the very high level `Benchee.run` API.
Intended Elixir interface.
"""
use Benchee.Impl
end

defmodule :benchee do
@moduledoc """
High-Level interface for more convenient usage from Erlang. Same as `Benchee`.
"""
use Benchee.Impl
end
15 changes: 15 additions & 0 deletions test/benchee_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ defmodule BencheeTest do
readme_sample_asserts output
end

test "erlang style :benchee integration" do
output = capture_io fn ->
list = Enum.to_list(1..10_000)
map_fun = fn(i) -> [i, i * i] end

:benchee.run(%{
"flat_map" => fn -> Enum.flat_map(list, map_fun) end,
"map.flatten" =>
fn -> list |> Enum.map(map_fun) |> List.flatten end
}, time: 0.01, warmup: 0.005)
end

readme_sample_asserts output
end

test "integration expanded README example" do
output = capture_io fn ->
list = Enum.to_list(1..10_000)
Expand Down

0 comments on commit 5ac381d

Please sign in to comment.