Skip to content

Instantly share code, notes, and snippets.

@neworld
Last active February 5, 2018 19:12
Show Gist options
  • Save neworld/d64261cd508e1484b7236bb8f6202349 to your computer and use it in GitHub Desktop.
Save neworld/d64261cd508e1484b7236bb8f6202349 to your computer and use it in GitHub Desktop.
package com.neworldwar
import com.neworldwar.utils.Random
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.RepeatedTest
import org.junit.jupiter.api.TestInstance
const val REQUESTS = 100
const val TOTAL_DEPENDENCIES = 1000
const val DEPENDENCIES_PER_REQUEST = 100
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MapPerformanceTest {
lateinit var map: Map<String, () -> Key>
@BeforeAll
internal fun setUp() {
map = (0 until TOTAL_DEPENDENCIES).map { it.toString() to { Key(it.toString()) } }.toMap()
}
@RepeatedTest(REQUESTS)
fun kodein() {
(1..DEPENDENCIES_PER_REQUEST).map { Random.randomInt(TOTAL_DEPENDENCIES) }
.forEach {
val key = map[it.toString()]!!()
println("found $key")
}
}
@RepeatedTest(REQUESTS)
fun dagger() {
(1..DEPENDENCIES_PER_REQUEST).map { Random.randomInt(TOTAL_DEPENDENCIES) }
.forEach {
val key = Key(it.toString())
println("found $key")
}
}
}
data class Key(val value: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment