This is an automated email from the ASF dual-hosted git repository.
rustyrazorblade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cassandra-easy-stress.git
The following commit(s) were added to refs/heads/main by this push:
new 830b47d Reuse RandomStringGenerator instead of allocating one per call
830b47d is described below
commit 830b47de5ab09ab18faaf23a64603b88e2e75427
Author: Jon Haddad <[email protected]>
AuthorDate: Fri Aug 7 23:29:43 2026 -0400
Reuse RandomStringGenerator instead of allocating one per call
Fixes #99
---
src/main/kotlin/org/apache/cassandra/easystress/Util.kt | 7 +++----
.../org/apache/cassandra/easystress/generators/functions/Random.kt | 5 +++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/kotlin/org/apache/cassandra/easystress/Util.kt
b/src/main/kotlin/org/apache/cassandra/easystress/Util.kt
index 03fdbcf..aee921d 100644
--- a/src/main/kotlin/org/apache/cassandra/easystress/Util.kt
+++ b/src/main/kotlin/org/apache/cassandra/easystress/Util.kt
@@ -25,12 +25,11 @@ Will be used later when adding configuration
*/
typealias Range<T> = Pair<T, T>
+private val randomStringGenerator =
RandomStringGenerator.Builder().withinRange(65, 90).build()
+
/*
Throwaway - will need to be thought out for
*/
-fun randomString(length: Int): String {
- val generator = RandomStringGenerator.Builder().withinRange(65, 90).build()
- return generator.generate(length)
-}
+fun randomString(length: Int): String = randomStringGenerator.generate(length)
fun round(num: Double): Double = DecimalFormat("##.##").format(num).toDouble()
diff --git
a/src/main/kotlin/org/apache/cassandra/easystress/generators/functions/Random.kt
b/src/main/kotlin/org/apache/cassandra/easystress/generators/functions/Random.kt
index 71e6992..04b40e7 100644
---
a/src/main/kotlin/org/apache/cassandra/easystress/generators/functions/Random.kt
+++
b/src/main/kotlin/org/apache/cassandra/easystress/generators/functions/Random.kt
@@ -31,6 +31,8 @@ class Random : FieldGenerator {
var min = 0L
var max = 100000L
+ private val stringGenerator =
RandomStringGenerator.Builder().withinRange(65, 90).build()
+
override fun setParameters(params: List<String>) {
min = HumanReadableConverter().convert(params[0])
max = HumanReadableConverter().convert(params[1])
@@ -47,8 +49,7 @@ class Random : FieldGenerator {
override fun getText(): String {
val length = ThreadLocalRandom.current().nextInt(min.toInt(),
max.toInt())
- val generator = RandomStringGenerator.Builder().withinRange(65,
90).build()
- return generator.generate(length)
+ return stringGenerator.generate(length)
}
companion object {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]