question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arb.stringPattern slows down the test dramatically

See original GitHub issue

I used to have this in my code

fun Arb.Companion.alphanumeric(): Arb<String> = Arb.stringPattern("[a-zA-Z0-9]+")

and used it everywhere. Tests became extremely slow after the upgrade to Kotest 4.3.1 (from 4.2.x). Let me know if you need more info.

A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sksamuelcommented, Dec 4, 2020

If you make the fix Mitchell I’ll release 4.3.2

On Fri, 4 Dec 2020, 05:25 Mitchell Yuwono, notifications@github.com wrote:

I think i might have found the root cause. Arb.pattern is instantiating Generex object on every sample. I managed to replicate this slowdown and confirmed that it is indeed a regression. It seems we need to cache the Generex object. I’ll raise a fix for that @sksamuel https://github.com/sksamuel

This is the arb https://github.com/kotest/kotest/blob/99138d177bd52feea19740abeec6c5c4a3ae11c1/kotest-property/src/jvmMain/kotlin/io/kotest/property/arbitrary/stringsjvm.kt#L7-L16

fun main() { val startCached = TimeSource.Monotonic.markNow() arbCachedPattern(“[a-zA-Z0-9]+”).take(10000).toList() println(“cached: ${startCached.elapsedNow()}”) // cached: 214ms

val startNotCached = TimeSource.Monotonic.markNow()
Arb.stringPattern("[a-zA-Z0-9]+").take(10000).toList()
println("not cached: ${startNotCached.elapsedNow()}")
// not cached: 2.71s

} // caching the Generex objectfun arbCachedPattern(pattern: String) = object : Arb<String>() { val generex = Generex(pattern) override fun edgecases(): List<String> = emptyList() override fun sample(rs: RandomSource): Sample<String> { generex.setSeed(rs.random.nextLong()) return sampleOf(generex.random(), StringShrinker) } }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kotest/kotest/issues/1878#issuecomment-738731469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGS2FQBTYY2GB73WEQTSTDBIZANCNFSM4ULGZPOA .

0reactions
sksamuelcommented, Dec 15, 2020

4.3.2 is released with this fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generators List | Kotest
Generator JVM JS Native arb.orNull() ✓ ✓ ✓ arb.orNull(nullProbability) ✓ ✓ ✓ Arb.boolean() ✓ ✓ ✓
Read more >
Log Viewer slows down your tests. How to prevent it?
Problem to solve. Katalon Studio's “Log Viewer” slows down your test execution significantly. Are you aware of this fact? Maybe not.
Read more >
Backend testing taxonomy - Scopes and Techniques
Otherwise, this would slow down tests substantially - considering start-up time ... Arb import io.kotest.property.arbitrary.filter import ...
Read more >
(PDF) Effects of Playing Surface (Hard and Clay Courts) on ...
Running time values in speed tests were not significantly different between CL and R. Running ... relative gentle bounce and slows down the...
Read more >
IMMMM bruh Flashcards | Quizlet
Which diagnostic tests should be considered when evaluating the cause of a ... is a neurological finding described as the slowing of movement...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found