mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-10-20 03:40:34 +00:00
remove shitty benchmark of coroutines
This commit is contained in:
@@ -1,16 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.jvm"
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
api project(":micro_utils.coroutines")
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.SmartSemaphore
|
|
||||||
import dev.inmo.micro_utils.coroutines.withAcquire
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.CoroutineStart
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.joinAll
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.io.File
|
|
||||||
import kotlin.math.tanh
|
|
||||||
import kotlin.system.measureNanoTime
|
|
||||||
|
|
||||||
data class Record(
|
|
||||||
val permits: Int,
|
|
||||||
val i: Int,
|
|
||||||
val timeNanos: Long
|
|
||||||
)
|
|
||||||
|
|
||||||
private const val permitsCount = 1000
|
|
||||||
private val acquiresCount = 10000
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
val outputFilePath = args.firstOrNull() ?: "local.bench.txt"
|
|
||||||
|
|
||||||
val records = ArrayList<Record>(permitsCount * acquiresCount)
|
|
||||||
val jobs = ArrayList<Job>()
|
|
||||||
val scope = CoroutineScope(Dispatchers.Default)
|
|
||||||
for (permits in 1 .. permitsCount) {
|
|
||||||
val semaphore = SmartSemaphore.Mutable(permits)
|
|
||||||
for (i in 0 until acquiresCount) {
|
|
||||||
jobs.add(
|
|
||||||
scope.launch(start = CoroutineStart.LAZY) {
|
|
||||||
val timeNanos = measureNanoTime {
|
|
||||||
semaphore.withAcquire {
|
|
||||||
tanh(57.179)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
records.add(Record(permits, i, timeNanos))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jobs.joinAll()
|
|
||||||
val file = File(outputFilePath)
|
|
||||||
file.writeText("")
|
|
||||||
val text = buildString {
|
|
||||||
records.groupBy { it.permits }.forEach {
|
|
||||||
it.value.sortedBy { it.i }.forEach {
|
|
||||||
append("${it.permits} ${it.i} ${it.timeNanos}\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.appendText(text)
|
|
||||||
file.appendText("\n")
|
|
||||||
println(text)
|
|
||||||
}
|
|
||||||
@@ -35,7 +35,6 @@ String[] includes = [
|
|||||||
":ktor:client",
|
":ktor:client",
|
||||||
":coroutines",
|
":coroutines",
|
||||||
":coroutines:compose",
|
":coroutines:compose",
|
||||||
":coroutines:benchmark",
|
|
||||||
":android:recyclerview",
|
":android:recyclerview",
|
||||||
":android:pickers",
|
":android:pickers",
|
||||||
":android:smalltextfield",
|
":android:smalltextfield",
|
||||||
|
|||||||
Reference in New Issue
Block a user