owaisqayum
Benchmark with benchee having separate inputs for same functions
Hi, i am trying to benchmark a function with different input but the results are getting shown in different HTML files.
my code:
map_fun = fn i -> [i, i * i] end
Benchee.run(
%{
"10 values" => fn input -> Enum.flat_map(input, map_fun) end,
"20 values" => fn input -> Enum.flat_map(input, map_fun) end,
"30 values" => fn input -> Enum.flat_map(input, map_fun) end
},
inputs: %{
:ten => 1..10,
:twenty => 1..20,
:thirty => 1..30
},
time: 10,
memory_time: 30,
formatters: [
{Benchee.Formatters.HTML, file: "samples_output/ex/ex.html"},
{Benchee.Formatters.Console, extended_statistics: true}
],
warmup: 30
)
I am getting results but the input :ten gets applied to all three functions in Benchee.run. All I want is to specify which input is for which run. Can I somehow do that with pattern matching?
Also, I don’t want to declare the list above Benchee.run, how can I do it with the help of inputs.
Thanks! 
Marked As Solved
devonestes
In this case, you want to just put the inputs in the function and not use the inputs feature. That’s designed for testing the same inputs against different functions, not for testing the same function against different inputs.
map_fun = fn i -> [i, i * i] end
Benchee.run(
%{
"10 values" => fn input -> Enum.flat_map(0..10, map_fun) end,
"20 values" => fn input -> Enum.flat_map(0..20, map_fun) end,
"30 values" => fn input -> Enum.flat_map(0..30, map_fun) end
},
time: 10,
memory_time: 30,
formatters: [
{Benchee.Formatters.HTML, file: "samples_output/ex/ex.html"},
{Benchee.Formatters.Console, extended_statistics: true}
],
warmup: 30
)
3
Popular in Questions
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
I have a list say
x = ["23gh", "56kh", "97mh"]
I would like to pass each element to Val in each iteration.
Say, in iteration 1 -------...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New







