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

Add missing toPersistentMap, rename persistentXxxOf to emptyPersistentXxx #177

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -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 {
Expand All @@ -35,7 +36,7 @@ open class AddAll {
*/
@Benchmark
fun addAllLast(): ImmutableList<String> {
return persistentListOf<String>().addAll(listToAdd)
return emptyPersistentList<String>().addAll(listToAdd)
}

/**
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/Get.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/Remove.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/Set.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableList/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import benchmarks.*
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.benchmark.*
import kotlinx.collections.immutable.emptyPersistentMap


/**
Expand All @@ -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() {
Expand Down
11 changes: 7 additions & 4 deletions benchmarks/commonMain/src/benchmarks/immutableMap/Equals.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableMap/Iterate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
9 changes: 5 additions & 4 deletions benchmarks/commonMain/src/benchmarks/immutableMap/PutAll.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/commonMain/src/benchmarks/immutableMap/Remove.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -38,8 +39,10 @@ open class Equals {

@Benchmark
fun equalsTrue() = persistentMap == sameMap

@Benchmark
fun nearlyEquals() = persistentMap == slightlyDifferentMap

@Benchmark
fun notEquals() = persistentMap == veryDifferentMap

Expand Down
Loading