Skip to content

[accidentally opened PR] #199

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

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/AddAll.kt
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import benchmarks.*
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class AddAll {
@@ -35,7 +36,7 @@ open class AddAll {
*/
@Benchmark
fun addAllLast(): ImmutableList<String> {
return persistentListOf<String>().addAll(listToAdd)
return emptyPersistentList<String>().addAll(listToAdd)
}

/**
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/Get.kt
Original file line number Diff line number Diff line change
@@ -9,13 +9,14 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class Get {
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
var size: Int = 0

private var persistentList: PersistentList<String> = persistentListOf()
private var persistentList: PersistentList<String> = emptyPersistentList()

@Setup
fun prepare() {
Original file line number Diff line number Diff line change
@@ -9,13 +9,14 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class Iterate {
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
var size: Int = 0

private var persistentList: PersistentList<String> = persistentListOf()
private var persistentList: PersistentList<String> = emptyPersistentList()

@Setup
fun prepare() {
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/Remove.kt
Original file line number Diff line number Diff line change
@@ -10,13 +10,14 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class Remove {
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
var size: Int = 0

private var persistentList: PersistentList<String> = persistentListOf()
private var persistentList: PersistentList<String> = emptyPersistentList()

@Setup
fun prepare() {
Original file line number Diff line number Diff line change
@@ -9,18 +9,19 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList
import kotlin.random.Random

@State(Scope.Benchmark)
open class RemoveAll {
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
var size: Int = 0

private var persistentList: PersistentList<Int> = persistentListOf()
private var persistentList: PersistentList<Int> = emptyPersistentList()

@Setup
fun prepare() {
persistentList = persistentListOf<Int>().addAll(List(size) { it })
persistentList = emptyPersistentList<Int>().addAll(List(size) { it })
}

// Results of the following benchmarks do not indicate memory or time spent per operation,
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableList
import benchmarks.*
import kotlinx.collections.immutable.PersistentList
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlin.random.Random

@@ -16,7 +17,7 @@ open class RemoveAllPredicate {
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
var size: Int = 0

private var persistentList = persistentListOf<String>()
private var persistentList = emptyPersistentList<String>()
private val truePredicate: (String) -> Boolean = { true }
private val falsePredicate: (String) -> Boolean = { false }
private var randomHalfElementsPredicate: (String) -> Boolean = truePredicate
@@ -39,7 +40,7 @@ open class RemoveAllPredicate {
tailElementsPredicate = { it in tailElements }

val allElements = List(size) { it.toString() }
persistentList = persistentListOf<String>().addAll(allElements)
persistentList = emptyPersistentList<String>().addAll(allElements)
}

// The benchmarks measure (time and memory spent in `removeAll` operation) / size
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/Set.kt
Original file line number Diff line number Diff line change
@@ -10,13 +10,14 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class Set {
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
var size: Int = 0

private var persistentList: PersistentList<String> = persistentListOf()
private var persistentList: PersistentList<String> = emptyPersistentList()
private var randomIndices = listOf<Int>()

@Setup
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class AddAll {
@@ -38,7 +39,7 @@ open class AddAll {
*/
@Benchmark
fun addAllLast(): PersistentList.Builder<String> {
val builder = persistentListOf<String>().builder()
val builder = emptyPersistentList<String>().builder()
builder.addAll(listToAdd)
return builder
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableList.builder
import benchmarks.*
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class Get {
@@ -17,7 +18,7 @@ open class Get {
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
var immutablePercentage: Double = 0.0

private var builder = persistentListOf<String>().builder()
private var builder = emptyPersistentList<String>().builder()

@Setup
fun prepare() {
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableList.builder
import benchmarks.*
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class Iterate {
@@ -17,7 +18,7 @@ open class Iterate {
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
var immutablePercentage: Double = 0.0

private var builder = persistentListOf<String>().builder()
private var builder = emptyPersistentList<String>().builder()

@Setup
fun prepare() {
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList
import kotlin.random.Random

@State(Scope.Benchmark)
@@ -84,7 +85,7 @@ open class RemoveAll {

private fun persistentListBuilderAddIndexes(): PersistentList.Builder<Int> {
val immutableSize = immutableSize(size, immutablePercentage)
var list = persistentListOf<Int>()
var list = emptyPersistentList<Int>()
for (i in 0 until immutableSize) {
list = list.add(i)
}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentList

@State(Scope.Benchmark)
open class Set {
@@ -18,7 +19,7 @@ open class Set {
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
var immutablePercentage: Double = 0.0

private var builder = persistentListOf<String>().builder()
private var builder = emptyPersistentList<String>().builder()
private var randomIndices = listOf<Int>()

@Setup
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/utils.kt
Original file line number Diff line number Diff line change
@@ -6,10 +6,11 @@
package benchmarks.immutableList

import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.emptyPersistentList
import kotlinx.collections.immutable.persistentListOf

fun persistentListAdd(size: Int): PersistentList<String> {
var list = persistentListOf<String>()
var list = emptyPersistentList<String>()
repeat(times = size) {
list = list.add("some element")
}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap


/**
@@ -35,13 +36,13 @@ open class Canonicalization {

private var keys = listOf<IntWrapper>()
private var keysToRemove = listOf<IntWrapper>()
private var persistentMap = persistentMapOf<IntWrapper, String>()
private var persistentMap = emptyPersistentMap<IntWrapper, String>()

/**
* Expected height of this persistent map is equal to the [persistentMap]'s expected height divided by 2.
* Obtained by removing some entries of the [persistentMap].
*/
private var halfHeightPersistentMap = persistentMapOf<IntWrapper, String>()
private var halfHeightPersistentMap = emptyPersistentMap<IntWrapper, String>()

@Setup
fun prepare() {
11 changes: 7 additions & 4 deletions benchmarks/commonMain/src/benchmarks/immutableMap/Equals.kt
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ package benchmarks.immutableMap

import benchmarks.*
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap
import kotlinx.collections.immutable.persistentMapOf

@State(Scope.Benchmark)
@@ -20,10 +21,10 @@ open class Equals {
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
var hashCodeType = ""

private var persistentMap = persistentMapOf<IntWrapper, String>()
private var sameMap = persistentMapOf<IntWrapper, String>()
private var slightlyDifferentMap = persistentMapOf<IntWrapper, String>()
private var veryDifferentMap = persistentMapOf<IntWrapper, String>()
private var persistentMap = emptyPersistentMap<IntWrapper, String>()
private var sameMap = emptyPersistentMap<IntWrapper, String>()
private var slightlyDifferentMap = emptyPersistentMap<IntWrapper, String>()
private var veryDifferentMap = emptyPersistentMap<IntWrapper, String>()

@Setup
fun prepare() {
@@ -36,8 +37,10 @@ open class Equals {

@Benchmark
fun equalsTrue() = persistentMap == sameMap

@Benchmark
fun nearlyEquals() = persistentMap == slightlyDifferentMap

@Benchmark
fun notEquals() = persistentMap == veryDifferentMap
}
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableMap/Get.kt
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableMap
import benchmarks.*
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap

@State(Scope.Benchmark)
open class Get {
@@ -21,7 +22,7 @@ open class Get {
var hashCodeType = ""

private var keys = listOf<IntWrapper>()
private var persistentMap = persistentMapOf<IntWrapper, String>()
private var persistentMap = emptyPersistentMap<IntWrapper, String>()

@Setup
fun prepare() {
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableMap/Iterate.kt
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableMap
import benchmarks.*
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap

@State(Scope.Benchmark)
open class Iterate {
@@ -20,7 +21,7 @@ open class Iterate {
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
var hashCodeType = ""

private var persistentMap = persistentMapOf<IntWrapper, String>()
private var persistentMap = emptyPersistentMap<IntWrapper, String>()

@Setup
fun prepare() {
9 changes: 5 additions & 4 deletions benchmarks/commonMain/src/benchmarks/immutableMap/PutAll.kt
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableMap
import benchmarks.*
import kotlinx.collections.immutable.PersistentMap
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap
import kotlinx.collections.immutable.persistentMapOf

@State(Scope.Benchmark)
@@ -21,10 +22,10 @@ open class PutAll {
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
var hashCodeType = ""

private var lhs = persistentMapOf<IntWrapper, String>()
private var lhsSmall = persistentMapOf<IntWrapper, String>()
private var rhs = persistentMapOf<IntWrapper, String>()
private var rhsSmall = persistentMapOf<IntWrapper, String>()
private var lhs = emptyPersistentMap<IntWrapper, String>()
private var lhsSmall = emptyPersistentMap<IntWrapper, String>()
private var rhs = emptyPersistentMap<IntWrapper, String>()
private var rhsSmall = emptyPersistentMap<IntWrapper, String>()

@Setup
fun prepare() {
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableMap/Remove.kt
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap

@State(Scope.Benchmark)
open class Remove {
@@ -22,7 +23,7 @@ open class Remove {
var hashCodeType = ""

private var keys = listOf<IntWrapper>()
private var persistentMap = persistentMapOf<IntWrapper, String>()
private var persistentMap = emptyPersistentMap<IntWrapper, String>()

@Setup
fun prepare() {
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ package benchmarks.immutableMap.builder

import benchmarks.*
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap
import kotlinx.collections.immutable.persistentMapOf

@State(Scope.Benchmark)
@@ -20,10 +21,10 @@ open class Equals {
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
var hashCodeType = ""

private var persistentMap = persistentMapOf<IntWrapper, String>().builder()
private var sameMap = persistentMapOf<IntWrapper, String>().builder()
private var slightlyDifferentMap = persistentMapOf<IntWrapper, String>().builder()
private var veryDifferentMap = persistentMapOf<IntWrapper, String>().builder()
private var persistentMap = emptyPersistentMap<IntWrapper, String>().builder()
private var sameMap = emptyPersistentMap<IntWrapper, String>().builder()
private var slightlyDifferentMap = emptyPersistentMap<IntWrapper, String>().builder()
private var veryDifferentMap = emptyPersistentMap<IntWrapper, String>().builder()

@Setup
fun prepare() {
@@ -38,8 +39,10 @@ open class Equals {

@Benchmark
fun equalsTrue() = persistentMap == sameMap

@Benchmark
fun nearlyEquals() = persistentMap == slightlyDifferentMap

@Benchmark
fun notEquals() = persistentMap == veryDifferentMap

Loading