-
Notifications
You must be signed in to change notification settings - Fork 1
/
jmh.sc
67 lines (56 loc) · 1.79 KB
/
jmh.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This file is copied from https://github.com/lihaoyi/mill/blob/master/integration/test/resources/play-json/jmh.sc
// Copyright (c) 2017 Li Haoyi ([email protected])
// MIT License
import mill._, scalalib._, modules._
trait Jmh extends ScalaModule {
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.openjdk.jmh:jmh-core:1.19")
def runJmh(args: String*) = T.command {
val (_, resources) = generateBenchmarkSources()
Jvm.runSubprocess(
"org.openjdk.jmh.Main",
classPath = (runClasspath() ++ generatorDeps()).map(_.path) ++
Seq(compileGeneratedSources().path, resources),
mainArgs = args,
workingDir = T.ctx.dest
)
}
def compileGeneratedSources = T {
val dest = T.ctx.dest
val (sourcesDir, _) = generateBenchmarkSources()
val sources = os.walk(sourcesDir).filter(os.isFile)
os.proc(
"javac",
sources.map(_.toString),
"-cp",
(runClasspath() ++ generatorDeps()).map(_.path.toString).mkString(":"),
"-d",
dest
)
.call(dest)
PathRef(dest)
}
// returns sources and resources directories
def generateBenchmarkSources = T {
val dest = T.ctx.dest
val sourcesDir = dest / "jmh_sources"
val resourcesDir = dest / "jmh_resources"
os.remove.all(sourcesDir)
os.makeDir.all(sourcesDir)
os.remove.all(resourcesDir)
os.makeDir.all(resourcesDir)
Jvm.runSubprocess(
"org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator",
(runClasspath() ++ generatorDeps()).map(_.path),
mainArgs = Array(
compile().classes.path,
sourcesDir,
resourcesDir,
"default"
).map(_.toString)
)
(sourcesDir, resourcesDir)
}
def generatorDeps = resolveDeps(
T { Agg(ivy"org.openjdk.jmh:jmh-generator-bytecode:1.19") }
)
}