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

Commit 35383c6

Browse files
committed
コンストラクタのベンチマークを追加
1 parent 1223159 commit 35383c6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.Constructor
10+
import kotlin.reflect.KFunction
11+
import kotlin.reflect.KParameter
12+
import kotlin.reflect.jvm.javaConstructor
13+
14+
@State(Scope.Benchmark)
15+
open class CallConstructorBenchmark {
16+
private val argument = 1
17+
18+
private val function: KFunction<Constructor1> = ::Constructor1
19+
private val argumentMap: Map<KParameter, Any?> = mapOf(function.parameters.single() to argument)
20+
21+
private val javaConstructor: Constructor<Constructor1> = function.javaConstructor!!
22+
private val fastKFunction: FastKFunction<Constructor1> = FastKFunction.of(function)
23+
private val singleArgFastKFunction: SingleArgFastKFunction<Constructor1> = SingleArgFastKFunction.of(function)
24+
25+
@Benchmark
26+
fun normalCall(): Constructor1 = Constructor1(argument)
27+
28+
@Benchmark
29+
fun kFunctionCall(): Constructor1 = function.call(argument)
30+
31+
@Benchmark
32+
fun kFunctionCallBy(): Constructor1 = function.callBy(argumentMap)
33+
34+
@Benchmark
35+
fun javaConstructor(): Constructor1 = javaConstructor.newInstance(argument)
36+
37+
@Benchmark
38+
fun fastKFunctionCall(): Constructor1 = fastKFunction.call(argument)
39+
40+
@Benchmark
41+
fun singleArgFastKFunctionCall(): Constructor1 = singleArgFastKFunction.call(argument)
42+
}

0 commit comments

Comments
 (0)