owaisqayum

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! :smiley:

Marked As Solved

devonestes

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
)

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement