// Massivin header-i ilə eyni cache line-da olan sayğac: başqa thread-in yoxlaması onu yavaşladır import java.util.concurrent.atomic.AtomicLongArray import kotlin.concurrent.thread fun run(first: Int, second: Int): Long { val c = AtomicLongArray(128) val t0 = System.nanoTime() val a = thread { repeat(100_000_000) { c.incrementAndGet(first) } } val b = thread { repeat(100_000_000) { c.incrementAndGet(second) } } a.join(); b.join() return (System.nanoTime() - t0) / 1_000_000 } fun main() { run(64, 96) // isinmə for ((f, s) in listOf(0 to 32, 64 to 96, 0 to 64, 1 to 64, 2 to 64)) { val t = List(5) { run(f, s) }.sorted() println("first=$f second=$s median ${t[2]} ms $t") } }