Update BigIntBenchmark.kt

unify definition (pow function seems to work wrong
This commit is contained in:
Alexander Nozik 2021-04-17 09:46:10 +03:00 committed by GitHub
parent 41d0be8085
commit 3dc7038b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,16 +12,17 @@ import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import space.kscience.kmath.operations.*
private fun BigInt.pow(power: Int): BigInt = modPow(BigIntField.number(power), BigInt.ONE)
@State(Scope.Benchmark)
internal class BigIntBenchmark {
val kmNumber = BigIntField.number(Int.MAX_VALUE)
val largeKmNumber = BigIntField {
fun BigInt.pow10(): BigInt = power(10, ::multiply)
number(11).pow10().pow10().pow10().pow10().pow10()
}
val jvmNumber = JBigIntegerField.number(Int.MAX_VALUE)
val largeJvmNumber = JBigIntegerField { number(11).pow(100_000) }
val largeKmNumber = BigIntField { number(11).pow(100_000) }
val largeJvmNumber = JBigIntegerField { number(11).pow(100_000) }
val bigExponent = 50_000
@Benchmark
@ -41,7 +42,7 @@ internal class BigIntBenchmark {
@Benchmark
fun kmMultiplyLarge(blackhole: Blackhole) = BigIntField {
blackhole.consume(largeKmNumber.let { it * it })
blackhole.consume(largeKmNumber*largeKmNumber)
}
@Benchmark
@ -51,12 +52,12 @@ internal class BigIntBenchmark {
@Benchmark
fun jvmMultiplyLarge(blackhole: Blackhole) = JBigIntegerField {
blackhole.consume(largeJvmNumber.let { it * it })
blackhole.consume(largeJvmNumber*largeJvmNumber)
}
@Benchmark
fun kmPower(blackhole: Blackhole) = BigIntField {
blackhole.consume(kmNumber.power(bigExponent, ::multiply))
blackhole.consume(kmNumber.pow(bigExponent))
}
@Benchmark