-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for macos, ios, linux targets across x86 and ARM
- Loading branch information
1 parent
ad2f266
commit cbd73b7
Showing
41 changed files
with
876 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
...tiveMain/kotlin/io/github/charlietap/cachemap/benchmark/CacheMapMultiThreadedBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.github.charlietap.cachemap.benchmark | ||
|
||
// Todo enable threading | ||
class CacheMapMultiThreadedBenchmark : CacheMapSingleThreadBenchmark() |
88 changes: 88 additions & 0 deletions
88
...ativeMain/kotlin/io/github/charlietap/cachemap/benchmark/CacheMapSingleThreadBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.github.charlietap.cachemap.benchmark | ||
|
||
import io.github.charlietap.cachemap.cacheMapOf | ||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.benchmark.BenchmarkMode | ||
import kotlinx.benchmark.BenchmarkTimeUnit | ||
import kotlinx.benchmark.Blackhole | ||
import kotlinx.benchmark.Measurement | ||
import kotlinx.benchmark.Mode | ||
import kotlinx.benchmark.OutputTimeUnit | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.Setup | ||
import kotlinx.benchmark.State | ||
import kotlinx.benchmark.TearDown | ||
import kotlinx.benchmark.Warmup | ||
|
||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Mode.AverageTime, Mode.Throughput) | ||
@OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) | ||
@Warmup(iterations = BenchmarkConfig.WARMUP_ITERATIONS) | ||
@Measurement(iterations = BenchmarkConfig.MEASUREMENT_ITERATIONS, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
class CacheMapSingleThreadBenchmark { | ||
|
||
private val cacheMap = cacheMapOf<String, String>() | ||
|
||
@Setup() | ||
fun setup() { | ||
for (i in 1..1000) { | ||
cacheMap.put("key$i", "value$i") | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun put(blackhole: Blackhole) { | ||
val result = cacheMap.put("Hello", "World") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun overwrite(blackhole: Blackhole) { | ||
val result = cacheMap.put("key1", "value2") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun putAll(blackhole: Blackhole) { | ||
val anotherMap = mapOf("Hello" to "World", "SecondKey" to "SecondValue") | ||
val result = cacheMap.putAll(anotherMap) | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun get(blackhole: Blackhole) { | ||
val result: String? = cacheMap["key1"] | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun getMiss(blackhole: Blackhole) { | ||
val result: String? = cacheMap["Hello"] | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun remove(blackhole: Blackhole) { | ||
val result = cacheMap.remove("key1") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun stressTest(blackhole: Blackhole) { | ||
for (i in 1..1000) { | ||
val putResult = cacheMap.put("newKey$i", "newValue$i") | ||
blackhole.consume(putResult) | ||
|
||
val getResult: String? = cacheMap["key$i"] | ||
blackhole.consume(getResult) | ||
|
||
val removeResult = cacheMap.remove("newKey$i") | ||
blackhole.consume(removeResult) | ||
} | ||
} | ||
|
||
@TearDown() | ||
fun tearDown() { | ||
cacheMap.clear() | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...iveMain/kotlin/io/github/charlietap/cachemap/benchmark/RWHashMapMultiThreadedBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.github.charlietap.cachemap.benchmark | ||
|
||
// todo add threads | ||
class RWHashMapMultiThreadedBenchmark : RWHashMapSingleThreadedBenchmark() |
108 changes: 108 additions & 0 deletions
108
...veMain/kotlin/io/github/charlietap/cachemap/benchmark/RWHashMapSingleThreadedBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package io.github.charlietap.cachemap.benchmark | ||
|
||
import kotlinx.atomicfu.locks.ReentrantLock | ||
import kotlinx.atomicfu.locks.withLock | ||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.benchmark.BenchmarkMode | ||
import kotlinx.benchmark.BenchmarkTimeUnit | ||
import kotlinx.benchmark.Blackhole | ||
import kotlinx.benchmark.Measurement | ||
import kotlinx.benchmark.Mode | ||
import kotlinx.benchmark.OutputTimeUnit | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.Setup | ||
import kotlinx.benchmark.State | ||
import kotlinx.benchmark.TearDown | ||
import kotlinx.benchmark.Warmup | ||
|
||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Mode.AverageTime, Mode.Throughput) | ||
@OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) | ||
@Warmup(iterations = BenchmarkConfig.WARMUP_ITERATIONS) | ||
@Measurement(iterations = BenchmarkConfig.MEASUREMENT_ITERATIONS, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
class RWHashMapSingleThreadedBenchmark { | ||
|
||
private val map = HashMap<String, String>() | ||
private val lock = ReentrantLock() | ||
|
||
@Setup() | ||
fun setup() { | ||
for (i in 1..1000) { | ||
map["key$i"] = "value$i" | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun put(blackhole: Blackhole) { | ||
val result = lock.withLock { | ||
map.put("Hello", "World") | ||
} | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun overwrite(blackhole: Blackhole) { | ||
val result = lock.withLock { | ||
map.put("key1", "value2") | ||
} | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun putAll(blackhole: Blackhole) { | ||
val anotherMap = mapOf("Hello" to "World", "SecondKey" to "SecondValue") | ||
lock.withLock { | ||
map.putAll(anotherMap) | ||
} | ||
blackhole.consume(anotherMap) | ||
} | ||
|
||
@Benchmark | ||
fun get(blackhole: Blackhole) { | ||
val result: String? = lock.withLock { | ||
map["key1"] | ||
} | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun getMiss(blackhole: Blackhole) { | ||
val result: String? = lock.withLock { | ||
map["Hello"] | ||
} | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun remove(blackhole: Blackhole) { | ||
val result = lock.withLock { | ||
map.remove("key1") | ||
} | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun stressTest(blackhole: Blackhole) { | ||
for (i in 1..1000) { | ||
val putResult = lock.withLock { | ||
map.put("newKey$i", "newValue$i") | ||
} | ||
blackhole.consume(putResult) | ||
|
||
val getResult: String? = lock.withLock { | ||
map["key$i"] | ||
} | ||
blackhole.consume(getResult) | ||
|
||
val removeResult = lock.withLock { | ||
map.remove("newKey$i") | ||
} | ||
blackhole.consume(removeResult) | ||
} | ||
} | ||
|
||
@TearDown() | ||
fun tearDown() { | ||
map.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.