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.

Revisions

  1. neworld revised this gist Feb 5, 2018. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions kodein_compare.kt
    Original file line number Diff line number Diff line change
    @@ -6,20 +6,21 @@ import org.junit.jupiter.api.RepeatedTest
    import org.junit.jupiter.api.TestInstance

    const val REQUESTS = 100
    const val DEPENDENCIES = 1000
    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 DEPENDENCIES).map { it.toString() to { Key(it.toString()) } }.toMap()
    map = (0 until TOTAL_DEPENDENCIES).map { it.toString() to { Key(it.toString()) } }.toMap()
    }

    @RepeatedTest(REQUESTS)
    fun kodein() {
    (1..100).map { Random.randomInt(DEPENDENCIES) }
    (1..DEPENDENCIES_PER_REQUEST).map { Random.randomInt(TOTAL_DEPENDENCIES) }
    .forEach {
    val key = map[it.toString()]!!()
    println("found $key")
    @@ -28,12 +29,12 @@ class MapPerformanceTest {

    @RepeatedTest(REQUESTS)
    fun dagger() {
    (1..100).map { Random.randomInt(DEPENDENCIES) }
    (1..DEPENDENCIES_PER_REQUEST).map { Random.randomInt(TOTAL_DEPENDENCIES) }
    .forEach {
    val key = Key(it.toString())
    println("found $key")
    }
    }
    }

    data class Key(val value: String)
    data class Key(val value: String)
  2. neworld created this gist Feb 5, 2018.
    39 changes: 39 additions & 0 deletions kodein_compare.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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 DEPENDENCIES = 1000

    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
    class MapPerformanceTest {
    lateinit var map: Map<String, () -> Key>

    @BeforeAll
    internal fun setUp() {
    map = (0 until DEPENDENCIES).map { it.toString() to { Key(it.toString()) } }.toMap()
    }

    @RepeatedTest(REQUESTS)
    fun kodein() {
    (1..100).map { Random.randomInt(DEPENDENCIES) }
    .forEach {
    val key = map[it.toString()]!!()
    println("found $key")
    }
    }

    @RepeatedTest(REQUESTS)
    fun dagger() {
    (1..100).map { Random.randomInt(DEPENDENCIES) }
    .forEach {
    val key = Key(it.toString())
    println("found $key")
    }
    }
    }

    data class Key(val value: String)