Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit c55afc4

Browse files
committed
トップレベル関数の呼び出し比較ベンチマークを追加
1 parent c988c34 commit c55afc4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.mapk.fastkfunction
2+
3+
import com.mapk.fastkfunction.argumentbucket.ArgumentBucket
4+
import com.mapk.fastkfunction.benchmarktargets.Constructor5
5+
import com.mapk.fastkfunction.benchmarktargets.topLevelFun5
6+
import org.openjdk.jmh.annotations.Benchmark
7+
import org.openjdk.jmh.annotations.Scope
8+
import org.openjdk.jmh.annotations.State
9+
import java.lang.reflect.Method
10+
import kotlin.reflect.KFunction
11+
import kotlin.reflect.KParameter
12+
import kotlin.reflect.jvm.javaMethod
13+
14+
@State(Scope.Benchmark)
15+
open class CallTopLevelFunBenchmark {
16+
private val function: KFunction<Constructor5> = ::topLevelFun5
17+
private val argumentMap: Map<KParameter, Any?> = function.parameters.associateWith { it.index + 1 }
18+
19+
private val javaMethod: Method = function.javaMethod!!
20+
private val fastKFunction: FastKFunction<Constructor5> = FastKFunction(function, null)
21+
private val argumentBucket: ArgumentBucket = fastKFunction.generateBucket()
22+
.apply { (0 until 5).forEach { this[it] = it + 1 } }
23+
24+
@Benchmark
25+
fun normalCall(): Constructor5 = topLevelFun5(1, 2, 3, 4, 5)
26+
27+
@Benchmark
28+
fun kFunctionCall(): Constructor5 = function.call(1, 2, 3, 4, 5)
29+
30+
@Benchmark
31+
fun kFunctionCallBy(): Constructor5 = function.callBy(argumentMap)
32+
33+
@Benchmark
34+
fun javaMethod(): Constructor5 = javaMethod.invoke(null, 1, 2, 3, 4, 5) as Constructor5
35+
36+
@Benchmark
37+
fun fastKFunctionCall(): Constructor5 = fastKFunction.call(1, 2, 3, 4, 5)
38+
39+
@Benchmark
40+
fun fastKFunctionCallBy(): Constructor5 = fastKFunction.callBy(argumentBucket)
41+
}

0 commit comments

Comments
 (0)