diff --git a/kmath-core/build.gradle b/kmath-core/build.gradle index 948dc87bf..18be067e6 100644 --- a/kmath-core/build.gradle +++ b/kmath-core/build.gradle @@ -1,6 +1,5 @@ plugins { - id 'kotlin-multiplatform'// version '1.3.0-rc-116' - id "me.champeau.gradle.jmh" version "0.4.7" + id 'kotlin-multiplatform' } repositories { @@ -8,14 +7,9 @@ repositories { mavenCentral() } -dependencies{ - jmh 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' -} - kotlin { targets { - fromPreset(presets.jvmWithJava, 'jvm') - //fromPreset(presets.jvm, 'jvm') + fromPreset(presets.jvm, 'jvm') fromPreset(presets.js, 'js') // For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64 // For Linux, preset should be changed to e.g. presets.linuxX64 diff --git a/kmath-jmh/build.gradle b/kmath-jmh/build.gradle new file mode 100644 index 000000000..a16bf3022 --- /dev/null +++ b/kmath-jmh/build.gradle @@ -0,0 +1,15 @@ +plugins { + id "java" + id "kotlin" + id "me.champeau.gradle.jmh" version "0.4.7" +} + +repositories { + maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' } + mavenCentral() +} + +dependencies { + implementation project(':kmath-core') + jmh 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' +} \ No newline at end of file diff --git a/kmath-jmh/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt b/kmath-jmh/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt new file mode 100644 index 000000000..eb40195e0 --- /dev/null +++ b/kmath-jmh/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt @@ -0,0 +1,53 @@ +package scientifik.kmath.structures + +import org.openjdk.jmh.annotations.* +import java.nio.IntBuffer + + +@Fork(1) +@Warmup(iterations = 2) +@Measurement(iterations = 5) +@State(Scope.Benchmark) +open class ArrayBenchmark { + + lateinit var array: IntArray + lateinit var arrayBuffer: IntBuffer + lateinit var nativeBuffer: IntBuffer + + @Setup + fun setup() { + array = IntArray(10000) { it } + arrayBuffer = IntBuffer.wrap(array) + nativeBuffer = IntBuffer.allocate(10000) + for (i in 0 until 10000) { + nativeBuffer.put(i,i) + } + } + + @Benchmark + fun benchmarkArrayRead() { + var res = 0 + for (i in 1..10000) { + res += array[10000 - i] + } + print(res) + } + + @Benchmark + fun benchmarkBufferRead() { + var res = 0 + for (i in 1..10000) { + res += arrayBuffer.get(10000 - i) + } + print(res) + } + + @Benchmark + fun nativeBufferRead() { + var res = 0 + for (i in 1..10000) { + res += nativeBuffer.get(10000 - i) + } + print(res) + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 03760221a..0e4b6fea7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,5 @@ enableFeaturePreview('GRADLE_METADATA') rootProject.name = 'kmath' include ':kmath-core' +include ':kmath-jmh'