v0.3.0-dev-9 #324
@ -5,19 +5,27 @@
|
|||||||
|
|
||||||
package space.kscience.kmath.benchmarks
|
package space.kscience.kmath.benchmarks
|
||||||
|
|
||||||
|
|
||||||
import kotlinx.benchmark.Blackhole
|
import kotlinx.benchmark.Blackhole
|
||||||
import org.openjdk.jmh.annotations.Benchmark
|
import org.openjdk.jmh.annotations.Benchmark
|
||||||
import org.openjdk.jmh.annotations.Scope
|
import org.openjdk.jmh.annotations.Scope
|
||||||
import org.openjdk.jmh.annotations.State
|
import org.openjdk.jmh.annotations.State
|
||||||
|
import space.kscience.kmath.operations.BigInt
|
||||||
import space.kscience.kmath.operations.BigIntField
|
import space.kscience.kmath.operations.BigIntField
|
||||||
import space.kscience.kmath.operations.JBigIntegerField
|
import space.kscience.kmath.operations.JBigIntegerField
|
||||||
import space.kscience.kmath.operations.invoke
|
import space.kscience.kmath.operations.invoke
|
||||||
|
|
||||||
|
private fun BigInt.pow(power: Int): BigInt = modPow(BigIntField.number(power), BigInt.ONE)
|
||||||
|
|
||||||
|
|
||||||
@State(Scope.Benchmark)
|
@State(Scope.Benchmark)
|
||||||
internal class BigIntBenchmark {
|
internal class BigIntBenchmark {
|
||||||
|
|
||||||
val kmNumber = BigIntField.number(Int.MAX_VALUE)
|
val kmNumber = BigIntField.number(Int.MAX_VALUE)
|
||||||
val jvmNumber = JBigIntegerField.number(Int.MAX_VALUE)
|
val jvmNumber = JBigIntegerField.number(Int.MAX_VALUE)
|
||||||
|
val largeKmNumber = BigIntField { number(11).pow(100_000) }
|
||||||
|
val largeJvmNumber = JBigIntegerField { number(11).pow(100_000) }
|
||||||
|
val bigExponent = 50_000
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
fun kmAdd(blackhole: Blackhole) = BigIntField {
|
fun kmAdd(blackhole: Blackhole) = BigIntField {
|
||||||
@ -34,8 +42,28 @@ internal class BigIntBenchmark {
|
|||||||
blackhole.consume(kmNumber * kmNumber * kmNumber)
|
blackhole.consume(kmNumber * kmNumber * kmNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun kmMultiplyLarge(blackhole: Blackhole) = BigIntField {
|
||||||
|
blackhole.consume(largeKmNumber*largeKmNumber)
|
||||||
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
fun jvmMultiply(blackhole: Blackhole) = JBigIntegerField {
|
fun jvmMultiply(blackhole: Blackhole) = JBigIntegerField {
|
||||||
blackhole.consume(jvmNumber * jvmNumber * jvmNumber)
|
blackhole.consume(jvmNumber * jvmNumber * jvmNumber)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Benchmark
|
||||||
|
fun jvmMultiplyLarge(blackhole: Blackhole) = JBigIntegerField {
|
||||||
|
blackhole.consume(largeJvmNumber*largeJvmNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun kmPower(blackhole: Blackhole) = BigIntField {
|
||||||
|
blackhole.consume(kmNumber.pow(bigExponent))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun jvmPower(blackhole: Blackhole) = JBigIntegerField {
|
||||||
|
blackhole.consume(jvmNumber.pow(bigExponent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user