0

I've read ScalaMeter docs and I don't understand how can I use it for benchmarking my project and not some atom hardcoded operations. Imagine I have the simple project

object SumBenchmark {
  def main(args: Array[String]): Unit = {
    val lst = List.fill(10000000)(1)
    lst.map(x => x + 1)
    val sum = lst.sum
  }
}

How can I use ScalaMeter to bench it? I mean something like

performance of "SumBenchmark" in {
    measure method "main" in {
      // I don't know what to write here but here should be some implementation of benchmarking
      }
    }
  }
Nourless
  • 729
  • 1
  • 5
  • 18
  • Do I get it correctly that you want to benchmark doing an increment for all numbers in a list and then do the sum of the all the outupts? – mfirry Jan 12 '21 at 11:23
  • I'd start by creating the `SumBenchmark` `object` inside `src/test/scala` with something like https://gist.github.com/mfirry/b393ed386e276190575780cd5202a55a and then you run it with `sbt test` or `sbt testOnly *SumBenchmark` – mfirry Jan 12 '21 at 11:29
  • @mfirry the point is i want to benchmark the perfomance of code contained in object. Summation of list is a minimum reproducable example. So your example is not very helpful because I want to say to ScalaMeter "measure this object" somehow. Imagine that SumBenchmark is a black box and I want to measure how is it working – Nourless Jan 12 '21 at 11:50
  • Right... then my guess would be instead of having ` r.map(_ + 1).sum` (for example in the link I provided) you would have a call to your logic you want to measure (say `mypackage.myObject.myFunc`) – mfirry Jan 12 '21 at 12:12
  • 1
    Have a look https://github.com/mfirry/so-65682326 – mfirry Jan 12 '21 at 12:26
  • Thanks it was very helpful. Can you also say me if ranges values denote hoy many times tests are carried? – Nourless Jan 12 '21 at 16:45
  • That should be covered by ScalaMeter docs – mfirry Jan 12 '21 at 16:48

1 Answers1

0

Assuming you have the usual Scala projecct structure

├── build.sbt
└── src
    ├── main
    │   └── scala
    │       └── myPackage
    │           └── MyThing.scala
    └── test
        └── scala
           └── myPackage
               └── MyThingBench.scala        

You basically put the logic you want to measure in the MyThingBench file

measure method "myfunction" in { myPackage.MyThing.myfunction() }
mfirry
  • 3,634
  • 1
  • 26
  • 36