aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/src/main/kotlin/benchmarks/common/BenchmarkUtils.kt
blob: 858ecfad67d4f9cc9a23ef5fb3f210ceb9901489 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package benchmarks.common

import java.util.concurrent.*

public fun doGeomDistrWork(work: Int) {
    // We use geometric distribution here. We also checked on macbook pro 13" (2017) that the resulting work times
    // are distributed geometrically, see https://github.com/Kotlin/kotlinx.coroutines/pull/1464#discussion_r355705325
    val p = 1.0 / work
    val r = ThreadLocalRandom.current()
    while (true) {
        if (r.nextDouble() < p) break
    }
}