Skip to content

Commit 50c59cb

Browse files
Add: Map bencmark
1 parent 8737198 commit 50c59cb

File tree

2 files changed

+82
-22
lines changed

2 files changed

+82
-22
lines changed
Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.utbot.benchmarks
22

3-
import org.junit.jupiter.api.RepeatedTest
43
import org.openjdk.jmh.annotations.Benchmark
54
import org.openjdk.jmh.annotations.Fork
65
import org.openjdk.jmh.annotations.Measurement
@@ -10,26 +9,37 @@ import org.openjdk.jmh.annotations.State
109
import org.openjdk.jmh.annotations.Threads
1110
import org.openjdk.jmh.annotations.Warmup
1211
import org.utbot.common.FileUtil
13-
import org.utbot.framework.plugin.api.TestCaseGenerator
12+
import org.utbot.examples.strings11.StringConcat
13+
import org.utbot.framework.UtSettings
14+
import org.utbot.framework.plugin.api.MockStrategyApi
15+
import org.utbot.framework.plugin.api.util.UtContext
16+
import org.utbot.framework.plugin.api.util.executableId
17+
import org.utbot.framework.plugin.api.util.withUtContext
1418
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
1519
import org.utbot.framework.util.SootUtils
1620
import org.utbot.tests.infrastructure.TestSpecificTestCaseGenerator
17-
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
18-
import org.utbot.tests.infrastructure.ignoreExecutionsNumber
1921
import java.util.concurrent.TimeUnit
2022

2123
@State(Scope.Benchmark)
2224
@Fork(1)
2325
@Threads(1)
24-
@Warmup(iterations = 3)
25-
@Measurement(iterations = 5, timeUnit = TimeUnit.SECONDS)
26-
class BenchmarksTest : UtValueTestCaseChecker(
27-
Benchmarks::class,
28-
) {
29-
lateinit var testCaseGenerator: TestCaseGenerator
26+
@Warmup(iterations = 2)
27+
@Measurement(iterations = 4, timeUnit = TimeUnit.SECONDS)
28+
class BenchmarksTest {
29+
lateinit var testCaseGenerator: TestSpecificTestCaseGenerator
30+
lateinit var context: UtContext
31+
3032
@Setup
3133
fun setUp() {
34+
UtSettings.utBotGenerationTimeoutInMillis = 200_000
35+
UtSettings.useFuzzing = false
36+
UtSettings.useConcreteExecution = false
37+
3238
val testClass = Benchmarks::class.java
39+
40+
context = UtContext(testClass.classLoader)
41+
UtContext.setUtContext(context)
42+
3343
SootUtils.runSoot(Benchmarks::class.java, true, JdkInfoDefaultProvider().info)
3444
testCaseGenerator = TestSpecificTestCaseGenerator(
3545
FileUtil.locateClassPath(testClass)!!.toPath(),
@@ -41,22 +51,52 @@ class BenchmarksTest : UtValueTestCaseChecker(
4151

4252
@Benchmark
4353
fun benchmarkLongMethod() {
44-
check(
45-
Benchmarks::longMethod,
46-
ignoreExecutionsNumber,
47-
{ x, y, r -> r == 1 },
48-
{ x, y, r -> r == 2 },
49-
)
54+
withUtContext(context) {
55+
testCaseGenerator.generate(
56+
Benchmarks::longMethod.executableId,
57+
MockStrategyApi.NO_MOCKS
58+
)
59+
}
5060
}
5161

5262

5363
@Benchmark
5464
fun benchmarkCycle() {
55-
check(
56-
Benchmarks::cycle,
57-
ignoreExecutionsNumber,
58-
{ _, r -> r == 1 },
59-
{ _, r -> r == 2 },
60-
)
65+
withUtContext(context) {
66+
testCaseGenerator.generate(
67+
Benchmarks::cycle.executableId,
68+
MockStrategyApi.NO_MOCKS
69+
)
70+
}
71+
}
72+
73+
@Benchmark
74+
fun benchmarkExceptionInToString() {
75+
withUtContext(context) {
76+
testCaseGenerator.generate(
77+
StringConcat::exceptionInToString.executableId,
78+
MockStrategyApi.NO_MOCKS
79+
)
80+
}
81+
}
82+
83+
@Benchmark
84+
fun benchmarkPutAndGet() {
85+
withUtContext(context) {
86+
testCaseGenerator.generate(
87+
Benchmarks::mapPutAndGet.executableId,
88+
MockStrategyApi.NO_MOCKS
89+
)
90+
}
91+
}
92+
93+
@Benchmark
94+
fun benchmarkPutInMapFromParameters() {
95+
withUtContext(context) {
96+
testCaseGenerator.generate(
97+
Benchmarks::putInMapFromParameters.executableId,
98+
MockStrategyApi.NO_MOCKS
99+
)
100+
}
61101
}
62102
}

utbot-framework-test/src/main/java/org/utbot/benchmarks/Benchmarks.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.utbot.benchmarks;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
36
interface Interface {
47
default int foo(int x) {
58
return x + bar();
@@ -697,4 +700,21 @@ public int interfaceCallMethod(int x) {
697700
public int bar() {
698701
return 2;
699702
}
703+
704+
Integer mapPutAndGet() {
705+
Map<Long, Integer> values = new HashMap<>();
706+
707+
values.put(1L, 2);
708+
values.put(1L, 3);
709+
710+
return values.get(1L);
711+
}
712+
713+
@SuppressWarnings("OverwrittenKey")
714+
Integer putInMapFromParameters(Map<Long, Integer> values) {
715+
values.put(1L, 2);
716+
values.put(1L, 3);
717+
718+
return values.get(1L);
719+
}
700720
}

0 commit comments

Comments
 (0)