From c79154b672b9c47b4fc991a757ca3481654eab8c Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Mon, 7 Dec 2020 03:03:21 +0700 Subject: [PATCH] Update manyRuns test --- kmath-ast/src/jsTest/kotlin/Test.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kmath-ast/src/jsTest/kotlin/Test.kt b/kmath-ast/src/jsTest/kotlin/Test.kt index 748cf6e0d..21f7efed0 100644 --- a/kmath-ast/src/jsTest/kotlin/Test.kt +++ b/kmath-ast/src/jsTest/kotlin/Test.kt @@ -1,9 +1,12 @@ package kscience.kmath.ast +import kscience.kmath.expressions.Expression +import kscience.kmath.expressions.StringSymbol import kscience.kmath.expressions.invoke import kscience.kmath.operations.IntRing import kscience.kmath.operations.RealField import kscience.kmath.wasm.compile +import kotlin.math.pow import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals @@ -44,12 +47,18 @@ internal class Test { var rng = Random(0) var sum1 = 0.0 var sum2 = 0.0 + var sum3 = 0.0 val e2 = RealField.mstInExtendedField { symbol("x").pow(1.0 / 6.0) } val e1 = e2.compile() measureTime { repeat(times) { sum1 += e1("x" to rng.nextDouble()) } }.also(::println) println("MST") rng = Random(0) measureTime { repeat(times) { sum2 += e2("x" to rng.nextDouble()) } }.also(::println) + val e3 = Expression { args -> args.getValue(StringSymbol("x")).pow(1.0 / 6.0) } + println("JS Math") + rng = Random(0) + measureTime { repeat(times) { sum3 += e3("x" to rng.nextDouble()) } }.also(::println) assertEquals(sum1, sum2) + assertEquals(sum1, sum3) } }