From 07ed9980fcd683048b15db88088f859d39ad6f4c Mon Sep 17 00:00:00 2001 From: margarita0303 Date: Wed, 13 Jul 2022 18:34:26 +0300 Subject: [PATCH] svd benchmarks added --- benchmarks/build.gradle.kts | 5 +++ .../kscience/kmath/benchmarks/SVDBenchmark.kt | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/SVDBenchmark.kt diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index f8d39b9c5..143681aec 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -84,6 +84,11 @@ benchmark { iterationTimeUnit = "ms" } + configurations.register("svd") { + commonConfiguration() + include("svdBenchmark") + } + configurations.register("buffer") { commonConfiguration() include("BufferBenchmark") diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/SVDBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/SVDBenchmark.kt new file mode 100644 index 000000000..e6fd716dd --- /dev/null +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/SVDBenchmark.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.benchmarks +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import space.kscience.kmath.tensors.core.BroadcastDoubleTensorAlgebra.svdGolabKahan +import space.kscience.kmath.tensors.core.DoubleTensorAlgebra +import space.kscience.kmath.tensors.core.DoubleTensorAlgebra.Companion.svd + +@State(Scope.Benchmark) +class SVDBenchmark { + companion object { + val tensor = DoubleTensorAlgebra.randomNormal(intArrayOf(10, 10, 10), 0) + } + + @Benchmark + fun svdPowerMethod(blackhole: Blackhole) { + blackhole.consume( + tensor.svd() + ) + } + + @Benchmark + fun svdGolabKahan(blackhole: Blackhole) { + blackhole.consume( + tensor.svdGolabKahan() + ) + } +} \ No newline at end of file