Last active
February 5, 2018 19:12
-
-
Save neworld/d64261cd508e1484b7236bb8f6202349 to your computer and use it in GitHub Desktop.
Revisions
-
neworld revised this gist
Feb 5, 2018 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal 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 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") @@ -28,12 +29,12 @@ class MapPerformanceTest { @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) -
neworld created this gist
Feb 5, 2018 .There are no files selected for viewing
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 charactersOriginal 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)