Dev #127

Merged
altavir merged 214 commits from dev into master 2020-08-11 08:33:21 +03:00
Showing only changes of commit c9de04a610 - Show all commits

View File

@ -1,21 +1,16 @@
package scientifik.kmath.ast package scientifik.kmath.ast
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import scientifik.kmath.asm.compile import scientifik.kmath.asm.compile
import scientifik.kmath.expressions.Expression import scientifik.kmath.expressions.Expression
import scientifik.kmath.expressions.expressionInField import scientifik.kmath.expressions.expressionInField
import scientifik.kmath.expressions.invoke
import scientifik.kmath.operations.Field import scientifik.kmath.operations.Field
import scientifik.kmath.operations.RealField import scientifik.kmath.operations.RealField
import kotlin.random.Random import kotlin.random.Random
import kotlin.system.measureTimeMillis
@State(Scope.Benchmark)
class ExpressionsInterpretersBenchmark { class ExpressionsInterpretersBenchmark {
private val algebra: Field<Double> = RealField private val algebra: Field<Double> = RealField
private val random: Random = Random(1)
@Benchmark
fun functionalExpression() { fun functionalExpression() {
val expr = algebra.expressionInField { val expr = algebra.expressionInField {
variable("x") * const(2.0) + const(2.0) / variable("x") - const(16.0) variable("x") * const(2.0) + const(2.0) / variable("x") - const(16.0)
@ -24,7 +19,6 @@ class ExpressionsInterpretersBenchmark {
invokeAndSum(expr) invokeAndSum(expr)
} }
@Benchmark
fun mstExpression() { fun mstExpression() {
val expr = algebra.mstInField { val expr = algebra.mstInField {
symbol("x") * number(2.0) + number(2.0) / symbol("x") - number(16.0) symbol("x") * number(2.0) + number(2.0) / symbol("x") - number(16.0)
@ -33,7 +27,6 @@ class ExpressionsInterpretersBenchmark {
invokeAndSum(expr) invokeAndSum(expr)
} }
@Benchmark
fun asmExpression() { fun asmExpression() {
val expr = algebra.mstInField { val expr = algebra.mstInField {
symbol("x") * number(2.0) + number(2.0) / symbol("x") - number(16.0) symbol("x") * number(2.0) + number(2.0) / symbol("x") - number(16.0)
@ -43,6 +36,7 @@ class ExpressionsInterpretersBenchmark {
} }
private fun invokeAndSum(expr: Expression<Double>) { private fun invokeAndSum(expr: Expression<Double>) {
val random = Random(0)
var sum = 0.0 var sum = 0.0
repeat(1000000) { repeat(1000000) {
@ -52,3 +46,25 @@ class ExpressionsInterpretersBenchmark {
println(sum) println(sum)
} }
} }
fun main() {
val benchmark = ExpressionsInterpretersBenchmark()
val fe = measureTimeMillis {
benchmark.functionalExpression()
}
println("fe=$fe")
val mst = measureTimeMillis {
benchmark.mstExpression()
}
println("mst=$mst")
val asm = measureTimeMillis {
benchmark.asmExpression()
}
println("asm=$asm")
}