From 2b4419823b774a1685fee08182f79b812980768e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 21 Jan 2019 17:01:11 +0300 Subject: [PATCH] Fixed performance tests. --- .../kmath/linear/LinearAlgebraBenchmark.kt | 12 +++++---- .../kmath/linear/MultiplicationBenchmark.kt | 25 +++++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt b/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt index d1bc92d8c..d57631eba 100644 --- a/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt +++ b/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt @@ -30,12 +30,14 @@ fun main() { //commons-math - val cmSolver = CMMatrixContext + val cmContext = CMMatrixContext val commonsTime = measureTimeMillis { - val cm = matrix.toCM() //avoid overhead on conversion - repeat(n) { - val res = cmSolver.inverse(cm) + cmContext.run { + val cm = matrix.toCM() //avoid overhead on conversion + repeat(n) { + val res = inverse(cm) + } } } @@ -50,7 +52,7 @@ fun main() { komaContext.run { val km = matrix.toKoma() //avoid overhead on conversion repeat(n) { - val res = cmSolver.inverse(km) + val res = inverse(km) } } } diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt b/benchmarks/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt index da56a0dd0..0b3b7c275 100644 --- a/benchmarks/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt +++ b/benchmarks/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt @@ -1,5 +1,6 @@ package scientifik.kmath.linear +import koma.matrix.ejml.EJMLMatrixFactory import kotlin.random.Random import kotlin.system.measureTimeMillis @@ -13,14 +14,28 @@ fun main() { // //warmup // matrix1 dot matrix2 - val cmMatrix1 = matrix1.toCM() - val cmMatrix2 = matrix2.toCM() + CMMatrixContext.run { + val cmMatrix1 = matrix1.toCM() + val cmMatrix2 = matrix2.toCM() - val cmTime = measureTimeMillis { - cmMatrix1 dot cmMatrix2 + val cmTime = measureTimeMillis { + cmMatrix1 dot cmMatrix2 + } + + println("CM implementation time: $cmTime") } - println("CM implementation time: $cmTime") + + KomaMatrixContext(EJMLMatrixFactory()).run { + val komaMatrix1 = matrix1.toKoma() + val komaMatrix2 = matrix2.toKoma() + + val komaTime = measureTimeMillis { + komaMatrix1 dot komaMatrix2 + } + + println("Koma-ejml implementation time: $komaTime") + } val genericTime = measureTimeMillis { val res = matrix1 dot matrix2