Skip to content

Commit

Permalink
fix: add benchmarking tests, update core version
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Jul 29, 2022
1 parent 791052a commit 80b8723
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ object Versions {
const val serializationPlugin = "1.6.20"
const val serializationRuntime = "1.3.2"
const val okhttp = "4.9.3"
const val evaluationCore = "0.0.1"
const val evaluationSerialization = "0.0.2"
const val evaluationCore = "1.0.0-rc1"
const val evaluationSerialization = "1.0.0"
}
60 changes: 60 additions & 0 deletions src/test/kotlin/LocalEvaluationClientTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.amplitude.experiment

import org.junit.Assert
import kotlin.system.measureNanoTime
import kotlin.system.measureTimeMillis
import kotlin.test.Test
import kotlin.time.measureTime

private const val API_KEY = "server-qz35UwzJ5akieoAdIgzM4m9MIiOLXLoz"

Expand Down Expand Up @@ -39,4 +42,61 @@ class LocalEvaluationClientTest {
val variant = variants["this-flag-doesnt-exit"]
Assert.assertNull(variant)
}

@Test
fun `test evaluate, benchmark 1 flag evaluation`() {
val client = LocalEvaluationClient(API_KEY)
client.start()
val duration = measureNanoTime {
client.evaluate(ExperimentUser(userId = "test_user"), listOf("sdk-local-evaluation-ci-test"))
}
val millis = duration / 1000.0 / 1000.0
Assert.assertTrue(millis < 10)
println("1 flag: $millis")
}

@Test
fun `test evaluate, benchmark 10 flag evaluations`() {
val client = LocalEvaluationClient(API_KEY)
client.start()
var total = 0L
repeat(1000) {
total += measureNanoTime {
client.evaluate(ExperimentUser(userId = "test_user"), listOf("sdk-local-evaluation-ci-test"))
}
}
val millis = total / 1000.0 / 1000.0
Assert.assertTrue(millis < 20)
println("10 flags: $millis")
}

@Test
fun `test evaluate, benchmark 100 flag evaluation`() {
val client = LocalEvaluationClient(API_KEY)
client.start()
var total = 0L
repeat(1000) {
total += measureNanoTime {
client.evaluate(ExperimentUser(userId = "test_user"), listOf("sdk-local-evaluation-ci-test"))
}
}
val millis = total / 1000.0 / 1000.0
Assert.assertTrue(millis < 20)
println("100 flags: $millis")
}

@Test
fun `test evaluate, benchmark 1000 flag evaluation`() {
val client = LocalEvaluationClient(API_KEY)
client.start()
var total = 0L
repeat(1000) {
total += measureNanoTime {
client.evaluate(ExperimentUser(userId = "test_user"), listOf("sdk-local-evaluation-ci-test"))
}
}
val millis = total / 1000.0 / 1000.0
Assert.assertTrue(millis < 100)
println("1000 flags: $millis")
}
}

0 comments on commit 80b8723

Please # to comment.