Last active
February 5, 2018 19:12
-
-
Save neworld/d64261cd508e1484b7236bb8f6202349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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