Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

scala - How should I use ScalaMeter for my project?

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
      }
    }
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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() }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...