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

Commit f7aa10d

Browse files
committed
インスタンス関数の呼び出しテストを追加
1 parent 0173537 commit f7aa10d

File tree

1 file changed

+48
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)