Skip to content

Commit a4e9fe1

Browse files
Draft: benchmarks
1 parent cb18154 commit a4e9fe1

File tree

4 files changed

+267
-0
lines changed

4 files changed

+267
-0
lines changed

utbot-framework-test/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
plugins {
2+
id 'org.jetbrains.kotlinx.benchmark' version '0.4.4'
3+
id 'org.jetbrains.kotlin.plugin.allopen' version "${kotlinVersion}"
4+
}
5+
16
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
27
kotlinOptions {
38
jvmTarget = JavaVersion.VERSION_11
@@ -84,3 +89,38 @@ test {
8489
jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009'
8590
}
8691
}
92+
93+
// Create a custom sourceSet
94+
sourceSets {
95+
benchmarks
96+
}
97+
98+
dependencies {
99+
benchmarksImplementation sourceSets.main.output + sourceSets.main.runtimeClasspath
100+
}
101+
102+
sourceSets.getByName("benchmarks") {
103+
dependencies {
104+
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.4")
105+
}
106+
}
107+
108+
allOpen {
109+
annotation("org.openjdk.jmh.annotations.State")
110+
}
111+
112+
113+
benchmark {
114+
// Setup configurations
115+
configurations {
116+
main { // main configuration is created automatically, but you can change its defaults
117+
mode = "avgt"
118+
}
119+
}
120+
targets {
121+
// This one matches sourceSet name above
122+
register("benchmarks") {
123+
jmhVersion = "1.35"
124+
}
125+
}
126+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.utbot.benchmarks
2+
3+
import org.junit.jupiter.api.RepeatedTest
4+
import org.openjdk.jmh.annotations.Benchmark
5+
import org.openjdk.jmh.annotations.Fork
6+
import org.openjdk.jmh.annotations.Measurement
7+
import org.openjdk.jmh.annotations.Scope
8+
import org.openjdk.jmh.annotations.Setup
9+
import org.openjdk.jmh.annotations.State
10+
import org.openjdk.jmh.annotations.Threads
11+
import org.openjdk.jmh.annotations.Warmup
12+
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
13+
import org.utbot.framework.util.SootUtils
14+
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
15+
import org.utbot.tests.infrastructure.ignoreExecutionsNumber
16+
import java.util.concurrent.TimeUnit
17+
18+
@State(Scope.Benchmark)
19+
@Fork(1)
20+
@Threads(1)
21+
@Warmup(iterations = 3)
22+
@Measurement(iterations = 5, timeUnit = TimeUnit.SECONDS)
23+
class BenchmarksTest : UtValueTestCaseChecker(
24+
Benchmarks::class,
25+
) {
26+
@Setup
27+
fun setUp() {
28+
SootUtils.runSoot(Benchmarks::class.java, true, JdkInfoDefaultProvider().info)
29+
}
30+
31+
@Benchmark
32+
@RepeatedTest(10)
33+
fun benchmarkLongMethod() {
34+
check(
35+
Benchmarks::longMethod,
36+
ignoreExecutionsNumber,
37+
{ x, y, r -> r == 1 },
38+
{ x, y, r -> r == 2 },
39+
)
40+
}
41+
42+
43+
@Benchmark
44+
fun benchmarkCycle() {
45+
check(
46+
Benchmarks::cycle,
47+
ignoreExecutionsNumber,
48+
{ _, r -> r == 1 },
49+
{ _, r -> r == 2 },
50+
)
51+
}
52+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.utbot.benchmarks
2+
3+
import org.utbot.common.FileUtil
4+
import org.utbot.framework.plugin.api.MockStrategyApi
5+
import org.utbot.framework.plugin.api.TestCaseGenerator
6+
import org.utbot.framework.plugin.api.util.UtContext
7+
import org.utbot.framework.plugin.api.util.executableId
8+
import org.utbot.framework.plugin.api.util.withUtContext
9+
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
10+
11+
fun main() {
12+
withUtContext(UtContext(ClassLoader.getSystemClassLoader())) {
13+
14+
val testClass = Benchmarks::class.java
15+
16+
val testCaseGenerator = TestCaseGenerator(
17+
listOf(FileUtil.locateClassPath(testClass)!!.toPath()),
18+
classpath = null,
19+
dependencyPaths = System.getProperty("java.class.path"),
20+
jdkInfo = JdkInfoDefaultProvider().info
21+
)
22+
23+
repeat(10) {
24+
testCaseGenerator.generate(
25+
listOf(
26+
Benchmarks::cycle.executableId
27+
),
28+
mockStrategy = MockStrategyApi.NO_MOCKS,
29+
generate = { engine -> engine.traverse() }
30+
)
31+
}
32+
33+
repeat(10) {
34+
testCaseGenerator.generate(
35+
listOf(
36+
Benchmarks::cycle.executableId
37+
),
38+
mockStrategy = MockStrategyApi.NO_MOCKS,
39+
generate = { engine -> engine.traverse() }
40+
)
41+
}
42+
}
43+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package org.utbot.benchmarks;
2+
3+
public class Benchmarks {
4+
5+
public int longMethod(int x, int y) {
6+
int[] arr = new int[200];
7+
8+
int cur = 1;
9+
{
10+
arr[cur] = x - y + arr[cur - 1];
11+
cur++;
12+
arr[cur] = x - y + arr[cur - 1];
13+
cur++;
14+
arr[cur] = x - y + arr[cur - 1];
15+
cur++;
16+
arr[cur] = x - y + arr[cur - 1];
17+
cur++;
18+
arr[cur] = x - y + arr[cur - 1];
19+
cur++;
20+
arr[cur] = x - y + arr[cur - 1];
21+
cur++;
22+
arr[cur] = x - y + arr[cur - 1];
23+
cur++;
24+
arr[cur] = x - y + arr[cur - 1];
25+
cur++;
26+
arr[cur] = x - y + arr[cur - 1];
27+
cur++;
28+
arr[cur] = x - y + arr[cur - 1];
29+
cur++;
30+
// 10
31+
arr[cur] = x - y + arr[cur - 1];
32+
cur++;
33+
arr[cur] = x - y + arr[cur - 1];
34+
cur++;
35+
arr[cur] = x - y + arr[cur - 1];
36+
cur++;
37+
arr[cur] = x - y + arr[cur - 1];
38+
cur++;
39+
arr[cur] = x - y + arr[cur - 1];
40+
cur++;
41+
arr[cur] = x - y + arr[cur - 1];
42+
cur++;
43+
arr[cur] = x - y + arr[cur - 1];
44+
cur++;
45+
arr[cur] = x - y + arr[cur - 1];
46+
cur++;
47+
arr[cur] = x - y + arr[cur - 1];
48+
cur++;
49+
arr[cur] = x - y + arr[cur - 1];
50+
cur++;
51+
// 20
52+
arr[cur] = x - y + arr[cur - 1];
53+
cur++;
54+
arr[cur] = x - y + arr[cur - 1];
55+
cur++;
56+
arr[cur] = x - y + arr[cur - 1];
57+
cur++;
58+
arr[cur] = x - y + arr[cur - 1];
59+
cur++;
60+
arr[cur] = x - y + arr[cur - 1];
61+
cur++;
62+
arr[cur] = x - y + arr[cur - 1];
63+
cur++;
64+
arr[cur] = x - y + arr[cur - 1];
65+
cur++;
66+
arr[cur] = x - y + arr[cur - 1];
67+
cur++;
68+
arr[cur] = x - y + arr[cur - 1];
69+
cur++;
70+
arr[cur] = x - y + arr[cur - 1];
71+
cur++;
72+
// 30
73+
arr[cur] = x - y + arr[cur - 1];
74+
cur++;
75+
arr[cur] = x - y + arr[cur - 1];
76+
cur++;
77+
arr[cur] = x - y + arr[cur - 1];
78+
cur++;
79+
arr[cur] = x - y + arr[cur - 1];
80+
cur++;
81+
arr[cur] = x - y + arr[cur - 1];
82+
cur++;
83+
arr[cur] = x - y + arr[cur - 1];
84+
cur++;
85+
arr[cur] = x - y + arr[cur - 1];
86+
cur++;
87+
arr[cur] = x - y + arr[cur - 1];
88+
cur++;
89+
arr[cur] = x - y + arr[cur - 1];
90+
cur++;
91+
arr[cur] = x - y + arr[cur - 1];
92+
cur++;
93+
// 40
94+
arr[cur] = x - y + arr[cur - 1];
95+
cur++;
96+
arr[cur] = x - y + arr[cur - 1];
97+
cur++;
98+
arr[cur] = x - y + arr[cur - 1];
99+
cur++;
100+
arr[cur] = x - y + arr[cur - 1];
101+
cur++;
102+
arr[cur] = x - y + arr[cur - 1];
103+
cur++;
104+
arr[cur] = x - y + arr[cur - 1];
105+
cur++;
106+
arr[cur] = x - y + arr[cur - 1];
107+
cur++;
108+
arr[cur] = x - y + arr[cur - 1];
109+
cur++;
110+
arr[cur] = x - y + arr[cur - 1];
111+
cur++;
112+
arr[cur] = x - y + arr[cur - 1];
113+
cur++;
114+
// 50
115+
}
116+
if (arr[cur - 1] == 100) {
117+
return 1;
118+
}
119+
return 2;
120+
}
121+
122+
public int cycle(int mx) {
123+
int res = 0;
124+
for (int i = 0; i <= mx; i++) {
125+
res += i;
126+
}
127+
if (res == 5050) {
128+
return 1;
129+
}
130+
return 2;
131+
}
132+
}

0 commit comments

Comments
 (0)