3

Just my first time with ScalaMeter and Scala. I'm trying to test two simple methods and I wrote, based on the samples given in the ScalaMeter Simple benchmark page the following code:

import org.scalameter.api._

object RangeBenchmark extends Bench.LocalTime {
  val sizes = Gen.range("size")(10, 150, 10)

  val ranges = for {
    size <- sizes
  } yield 0 until size

  def testPow(x: Double) = Math.pow(x, 5)
  def testMul(x: Int) = x * x * x * x * x

  performance of "Range" in {
    measure method "testMul" in {
        using(ranges) in { r =>
            r.foreach(testMul(_))
        }
    }

    measure method "testPow" in {
      using(ranges) in { r =>
        r.foreach(testPow(_))
      }
    }
  }
}

and it runs OK. But if I change the predefined test configuration from Bench.LocalTime to Bench.ForkedTime or Bench.OfflineReport I get the following error message:

Test threw exception: java.lang.ClassNotFoundException: org.scalameter.Parameters                                                                                                                                  java.lang.ClassNotFoundException: org.scalameter.Parameters
...
[error] Could not run test RangeBenchmark: java.lang.ClassNotFoundException: org.scalameter.Parameters

I'm running JDK 11, by the way.

So I have two questions:

  1. Any idea of what I'm doing wrong?
  2. Is this the correct way for testing simple methods or functions?

Thanks

Guidone
  • 31
  • 4
  • 1
    How do you run the test? I manage to run Bench.ForkedTime with a forked jvm through sbt, if I disabled fork, then I get the same exception as you – Qingwei Apr 26 '21 at 18:58
  • I had to add in root project settings the following: `[test config] / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat`, so eg. `Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat` – Nebril Feb 20 '23 at 07:54

0 Answers0