Skip to content

Commit 33f11d3

Browse files
committed
Benchmark for classpah lookup
1 parent 6184078 commit 33f11d3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package scala.tools.nsc
2+
3+
import java.nio.file.{Files, Paths}
4+
import java.util.concurrent.TimeUnit
5+
6+
import org.openjdk.jmh
7+
import org.openjdk.jmh.annotations._
8+
import org.openjdk.jmh.infra.Blackhole
9+
10+
import scala.tools.nsc
11+
import scala.tools.nsc.util.ClassPath
12+
import scala.tools.util.PathResolver
13+
14+
@BenchmarkMode(Array(jmh.annotations.Mode.AverageTime))
15+
@Fork(2)
16+
@Threads(1)
17+
@Warmup(iterations = 10)
18+
@Measurement(iterations = 10)
19+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
20+
@State(Scope.Benchmark)
21+
class AggregateClassPathBenchmark {
22+
@Param(Array(""))
23+
var classpathString: String = _
24+
var classpath: ClassPath = _
25+
val closeableRegistry = new CloseableRegistry
26+
@Setup def setup(): Unit = {
27+
val settings = new nsc.Settings()
28+
if (classpathString.startsWith("@"))
29+
classpathString = new String(Files.readAllBytes(Paths.get(classpathString.drop(1))))
30+
settings.classpath.value = classpathString
31+
val resolver = new PathResolver(settings, closeableRegistry)
32+
classpath = resolver.result
33+
classpath.list("")
34+
}
35+
36+
@TearDown def teardown(): Unit = {
37+
closeableRegistry.close()
38+
}
39+
40+
@Benchmark def test(bh: Blackhole) = {
41+
classpath.list("")._1.foreach(entry => bh.consume(classpath.list(entry.name)))
42+
}
43+
}

0 commit comments

Comments
 (0)