Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark other immutable collections frameworks #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/.idea/*
!/.idea/copyright
/benchmarks-libraries/.idea/*
!/benchmarks-libraries/.idea/copyright
.gradle
*.iml
target
Expand Down
6 changes: 6 additions & 0 deletions benchmarks-libraries/.idea/copyright/apache_2_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions benchmarks-libraries/.idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions benchmarks-libraries/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.40'
id "me.champeau.gradle.jmh" version "0.4.8"
}

repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url 'http://nexus.usethesource.io/content/repositories/public/' }
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

implementation 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.2-SNAPSHOT'
implementation 'io.usethesource:capsule:0.6.1'
implementation 'org.organicdesign:Paguro:3.1.2'
implementation 'com.oath.cyclops:cyclops:10.3.0'
implementation 'org.clojure:clojure:1.10.0'
implementation 'org.scala-lang:scala-library:2.13.0'
implementation 'io.vavr:vavr:0.9.3'
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}

compileJmhKotlin {
kotlinOptions.jvmTarget = "1.8"
}

task generateBenchmarkSources(type: JavaExec) {
main = 'generators.BenchmarkSourceGeneratorKt'
classpath = sourceSets.main.runtimeClasspath
}

jmh {
// include = ['immutableList.*.Add', 'immutableMap', 'immutableSet']
// exclude = ['builder']

profilers = ['gc']

resultFormat = "csv"

fork = 1
warmupIterations = 7
iterations = 10
warmup = '500ms'
timeOnIteration = '500ms'

benchmarkMode = ['avgt']
timeUnit = "us"

benchmarkParameters = [
'size':['1', '10', '100', '1000', '10000'],
// 'implementation': ['hash'],
'hashCodeType':['random', 'collision'],
'immutablePercentage':['0.0', '80.0']
]
}
Binary file not shown.
6 changes: 6 additions & 0 deletions benchmarks-libraries/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Jun 11 01:45:01 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-all.zip
17 changes: 17 additions & 0 deletions benchmarks-libraries/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2016-2019 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rootProject.name = 'Collection Frameworks Benchmarks'
38 changes: 38 additions & 0 deletions benchmarks-libraries/src/jmh/java/benchmarks/IntWrapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2016-2019 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Auto-generated file. DO NOT EDIT!

package benchmarks


class IntWrapper(val obj: Int, val hashCode: Int) : Comparable<IntWrapper> {
override fun hashCode(): Int {
return hashCode
}

override fun equals(other: Any?): Boolean {
if (other !is IntWrapper) {
return false
}
assert(obj != other.obj || hashCode == other.hashCode) // if elements are equal hashCodes must be equal
return obj == other.obj
}

override fun compareTo(other: IntWrapper): Int {
return obj.compareTo(other.obj)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* Copyright 2016-2019 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Auto-generated file. DO NOT EDIT!

package benchmarks.immutableList.clojure

import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.infra.Blackhole
import benchmarks.*

@State(Scope.Thread)
open class Add {
@Param("10000", "100000")
var size: Int = 0

@Benchmark
fun addLast(): clojure.lang.PersistentVector {
return persistentListAdd(size)
}

@Benchmark
fun addLastAndIterate(bh: Blackhole) {
val list = persistentListAdd(size)
for (e in list) {
bh.consume(e)
}
}

@Benchmark
fun addLastAndGet(bh: Blackhole) {
val list = persistentListAdd(size)
for (i in 0 until size) {
bh.consume(list.get(i))
}
}
}


@State(Scope.Thread)
open class Get {
@Param("10000", "100000")
var size: Int = 0

private var persistentList = clojure.lang.PersistentVector.EMPTY

@Setup(Level.Trial)
fun prepare() {
persistentList = persistentListAdd(size)
}

@Benchmark
fun getByIndex(bh: Blackhole) {
for (i in 0 until size) {
bh.consume(persistentList.get(i))
}
}
}


@State(Scope.Thread)
open class Iterate {
@Param("10000", "100000")
var size: Int = 0

private var persistentList = clojure.lang.PersistentVector.EMPTY

@Setup(Level.Trial)
fun prepare() {
persistentList = persistentListAdd(size)
}

@Benchmark
fun firstToLast(bh: Blackhole) {
for (e in persistentList) {
bh.consume(e)
}
}

@Benchmark
fun lastToFirst(bh: Blackhole) {
val iterator = persistentList.listIterator(size)

while (iterator.hasPrevious()) {
bh.consume(iterator.previous())
}
}
}


@State(Scope.Thread)
open class Remove {
@Param("10000", "100000")
var size: Int = 0

private var persistentList = clojure.lang.PersistentVector.EMPTY

@Setup(Level.Trial)
fun prepare() {
persistentList = persistentListAdd(size)
}

@Benchmark
fun removeLast(): clojure.lang.PersistentVector {
var list = persistentList
repeat(times = size) {
list = list.pop()
}
return list
}
}


@State(Scope.Thread)
open class Set {
@Param("10000", "100000")
var size: Int = 0

private var persistentList = clojure.lang.PersistentVector.EMPTY
private var randomIndices = listOf<Int>()

@Setup(Level.Trial)
fun prepare() {
persistentList = persistentListAdd(size)
randomIndices = List(size) { it }.shuffled()
}

@Benchmark
fun setByIndex(): clojure.lang.PersistentVector {
repeat(times = size) { index ->
persistentList = persistentList.assocN(index, "another element")
}
return persistentList
}

@Benchmark
fun setByRandomIndex(): clojure.lang.PersistentVector {
repeat(times = size) { index ->
persistentList = persistentList.assocN(randomIndices[index], "another element")
}
return persistentList
}
}


private fun persistentListAdd(size: Int): clojure.lang.PersistentVector {
var list = clojure.lang.PersistentVector.EMPTY
repeat(times = size) {
list = list.cons("some element")
}
return list
}
Loading