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

Commit a4e5af7

Browse files
committed
トップレベル関数向けベンチマークを追加
1 parent e544828 commit a4e5af7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.mapk.fastkfunction.singleargfastkfunction
2+
3+
import com.mapk.fastkfunction.FastKFunction
4+
import com.mapk.fastkfunction.SingleArgFastKFunction
5+
import com.mapk.fastkfunction.argumentbucket.ArgumentBucket
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 argument = 1
17+
18+
private val function: KFunction<Constructor1> = ::topLevelFun1
19+
private val argumentMap: Map<KParameter, Any?> = mapOf(function.parameters.single() to argument)
20+
21+
private val javaMethod: Method = function.javaMethod!!
22+
private val fastKFunction: FastKFunction<Constructor1> = FastKFunction.of(function, null)
23+
private val singleArgFastKFunction: SingleArgFastKFunction<Constructor1> =
24+
SingleArgFastKFunction.of(function, null)
25+
26+
@Benchmark
27+
fun normalCall(): Constructor1 = topLevelFun1(argument)
28+
29+
@Benchmark
30+
fun kFunctionCall(): Constructor1 = function.call(argument)
31+
32+
@Benchmark
33+
fun kFunctionCallBy(): Constructor1 = function.callBy(argumentMap)
34+
35+
@Benchmark
36+
fun javaMethod(): Constructor1 = javaMethod.invoke(null, argument) as Constructor1
37+
38+
@Benchmark
39+
fun fastKFunctionCall(): Constructor1 = fastKFunction.call(argument)
40+
41+
@Benchmark
42+
fun singleArgFastKFunctionCall(): Constructor1 = singleArgFastKFunction.call(argument)
43+
}

0 commit comments

Comments
 (0)