Update benchmark
This commit is contained in:
parent
3b52eb7ac1
commit
3dc59ccd26
@ -1,7 +1,7 @@
|
||||
package scientifik.kmath.bignum
|
||||
|
||||
import com.ionspin.kotlin.bignum.integer.BigInteger
|
||||
import scientifik.kmath.operations.BigIntField
|
||||
import scientifik.kmath.operations.JBigIntegerField
|
||||
import scientifik.kmath.operations.invoke
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.random.Random
|
||||
@ -9,30 +9,26 @@ import kotlin.system.measureTimeMillis
|
||||
|
||||
private class BigIntegerBenchmark {
|
||||
fun java() {
|
||||
invokeAndSum { l, l2 -> (l.toBigInteger() * l2.toBigInteger()).toLong() }
|
||||
val random = Random(0)
|
||||
var sum = JBigIntegerField.zero
|
||||
repeat(1000000) {
|
||||
sum += JBigIntegerField { number(random.nextInt()) * random.nextInt() }
|
||||
}
|
||||
println("java:$sum")
|
||||
}
|
||||
|
||||
fun bignum() {
|
||||
invokeAndSum { l, l2 -> (BigInteger.fromLong(l) * BigInteger.fromLong(l2)).longValue() }
|
||||
val random = Random(0)
|
||||
var sum = BigIntegerRing.zero
|
||||
repeat(1000000) { sum += BigIntegerRing { number(random.nextInt()) * random.nextInt() } }
|
||||
println("bignum:$sum")
|
||||
}
|
||||
|
||||
fun bigint() {
|
||||
invokeAndSum { l, l2 -> BigIntField { number(l) * number(l2) }.toString().toLong() }
|
||||
}
|
||||
|
||||
fun long() {
|
||||
invokeAndSum { l, l2 -> l * l2 }
|
||||
}
|
||||
|
||||
private fun invokeAndSum(op: (Long, Long) -> Long) {
|
||||
val random = Random(0)
|
||||
var sum = 0.0
|
||||
|
||||
repeat(1000000) {
|
||||
sum += op(random.nextInt().toLong(), random.nextInt().toLong())
|
||||
}
|
||||
|
||||
println(sum)
|
||||
var sum = BigIntField.zero
|
||||
repeat(1000000) { sum += BigIntField { number(random.nextInt()) * random.nextInt() } }
|
||||
println("bigint:$sum")
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,9 +49,4 @@ fun main() {
|
||||
val bigint = measureTimeMillis(benchmark::bigint)
|
||||
println("bigint=$bigint")
|
||||
}
|
||||
|
||||
thread {
|
||||
val long = measureTimeMillis(benchmark::long)
|
||||
println("long=$long")
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package scientifik.kmath.bignum
|
||||
import com.ionspin.kotlin.bignum.integer.BigInteger
|
||||
import scientifik.kmath.operations.Ring
|
||||
|
||||
class BigIntegerRing : Ring<BigInteger> {
|
||||
object BigIntegerRing : Ring<BigInteger> {
|
||||
override val zero: BigInteger
|
||||
get() = BigInteger.ZERO
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user