-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathBenchmark.kt
More file actions
85 lines (73 loc) · 2.88 KB
/
Benchmark.kt
File metadata and controls
85 lines (73 loc) · 2.88 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package org.utbot.examples.benchmark
import org.utbot.instrumentation.ConcreteExecutor
import org.utbot.instrumentation.instrumentation.InvokeInstrumentation
import org.utbot.instrumentation.instrumentation.coverage.InstructionCoverageInstrumentation
import org.utbot.instrumentation.instrumentation.coverage.collectCoverage
import org.utbot.instrumentation.util.Isolated
import kotlin.system.measureNanoTime
import org.junit.jupiter.api.Assertions.assertEquals
fun getBasicCoverageTime(count: Int): Double {
var time: Long
ConcreteExecutor(
InstructionCoverageInstrumentation.Factory,
Repeater::class.java.protectionDomain.codeSource.location.path
).use { executor ->
val dc0 = Repeater(", ")
val concat = Isolated(Repeater::concat, executor)
for (i in 0..20000) {
val res = concat(dc0, "flex", "mega-", 10)
assertEquals("mega-mega-mega-mega-mega-mega-mega-mega-mega-mega-flex", res.getOrNull())
}
time = measureNanoTime {
for (i in 0..count) {
val res = concat(dc0, "flex", "mega-", 10)
assertEquals("mega-mega-mega-mega-mega-mega-mega-mega-mega-mega-flex", res.getOrNull())
}
executor.collectCoverage(Repeater::class.java)
}
}
return time / 1e6
}
fun getNativeCallTime(count: Int): Double {
val dc0 = Repeater(", ")
for (i in 0..20000) {
val res0 = dc0.concat("flex", "mega-", 10)
assertEquals("mega-mega-mega-mega-mega-mega-mega-mega-mega-mega-flex", res0)
}
val time = measureNanoTime {
for (i in 0..count) {
dc0.concat("flex", "mega-", 10)
}
}
return time / 1e6
}
fun getJustResultTime(count: Int): Double {
var time: Long
ConcreteExecutor(
InvokeInstrumentation.Factory,
Repeater::class.java.protectionDomain.codeSource.location.path
).use {
val dc0 = Repeater(", ")
val concat = Isolated(Repeater::concat, it)
for (i in 0..20000) {
val res = concat(dc0, "flex", "mega-", 10)
assertEquals("mega-mega-mega-mega-mega-mega-mega-mega-mega-mega-flex", res.getOrNull())
}
time = measureNanoTime {
for (i in 0..count) {
concat(dc0, "flex", "mega-", 10)
}
}
}
return time / 1e6
}
fun main() {
val callsCount = 400_000
val nativeCallTime = getNativeCallTime(callsCount)
val basicCoverageTime = getBasicCoverageTime(callsCount)
val justResultTime = getJustResultTime(callsCount)
println("Running results on $callsCount method calls")
println("nativeCall: $nativeCallTime ms")
println("basicCoverage: $basicCoverageTime ms, overhead per call: ${(basicCoverageTime - nativeCallTime) / callsCount} ms")
println("justResult: $justResultTime ms, overhead per call: ${(justResultTime - nativeCallTime) / callsCount} ms")
}