Enable AST example
This commit is contained in:
parent
cdd196097e
commit
61e58c4302
@ -19,7 +19,7 @@ repositories {
|
|||||||
sourceSets.register("benchmarks")
|
sourceSets.register("benchmarks")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// implementation(project(":kmath-ast"))
|
implementation(project(":kmath-ast"))
|
||||||
implementation(project(":kmath-core"))
|
implementation(project(":kmath-core"))
|
||||||
implementation(project(":kmath-coroutines"))
|
implementation(project(":kmath-coroutines"))
|
||||||
implementation(project(":kmath-commons"))
|
implementation(project(":kmath-commons"))
|
||||||
|
@ -1,70 +1,70 @@
|
|||||||
package kscience.kmath.ast
|
package kscience.kmath.ast
|
||||||
//
|
|
||||||
//import kscience.kmath.asm.compile
|
import kscience.kmath.asm.compile
|
||||||
//import kscience.kmath.expressions.Expression
|
import kscience.kmath.expressions.Expression
|
||||||
//import kscience.kmath.expressions.expressionInField
|
import kscience.kmath.expressions.expressionInField
|
||||||
//import kscience.kmath.expressions.invoke
|
import kscience.kmath.expressions.invoke
|
||||||
//import kscience.kmath.operations.Field
|
import kscience.kmath.operations.Field
|
||||||
//import kscience.kmath.operations.RealField
|
import kscience.kmath.operations.RealField
|
||||||
//import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
//import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
//
|
|
||||||
//class ExpressionsInterpretersBenchmark {
|
class ExpressionsInterpretersBenchmark {
|
||||||
// private val algebra: Field<Double> = RealField
|
private val algebra: Field<Double> = RealField
|
||||||
// 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)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// invokeAndSum(expr)
|
invokeAndSum(expr)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// 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)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// invokeAndSum(expr)
|
invokeAndSum(expr)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// 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)
|
||||||
// }.compile()
|
}.compile()
|
||||||
//
|
|
||||||
// invokeAndSum(expr)
|
invokeAndSum(expr)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// private fun invokeAndSum(expr: Expression<Double>) {
|
private fun invokeAndSum(expr: Expression<Double>) {
|
||||||
// val random = Random(0)
|
val random = Random(0)
|
||||||
// var sum = 0.0
|
var sum = 0.0
|
||||||
//
|
|
||||||
// repeat(1000000) {
|
repeat(1000000) {
|
||||||
// sum += expr("x" to random.nextDouble())
|
sum += expr("x" to random.nextDouble())
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// println(sum)
|
println(sum)
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//fun main() {
|
fun main() {
|
||||||
// val benchmark = ExpressionsInterpretersBenchmark()
|
val benchmark = ExpressionsInterpretersBenchmark()
|
||||||
//
|
|
||||||
// val fe = measureTimeMillis {
|
val fe = measureTimeMillis {
|
||||||
// benchmark.functionalExpression()
|
benchmark.functionalExpression()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// println("fe=$fe")
|
println("fe=$fe")
|
||||||
//
|
|
||||||
// val mst = measureTimeMillis {
|
val mst = measureTimeMillis {
|
||||||
// benchmark.mstExpression()
|
benchmark.mstExpression()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// println("mst=$mst")
|
println("mst=$mst")
|
||||||
//
|
|
||||||
// val asm = measureTimeMillis {
|
val asm = measureTimeMillis {
|
||||||
// benchmark.asmExpression()
|
benchmark.asmExpression()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// println("asm=$asm")
|
println("asm=$asm")
|
||||||
//}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user