Skip to content

Commit b36baf4

Browse files
Merge branch 'main' into varhandle
2 parents 9a73165 + 5ddaf04 commit b36baf4

File tree

12 files changed

+536
-381
lines changed

12 files changed

+536
-381
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ cash-licensee = { id = "app.cash.licensee", version = "1.6.0" }
4545
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.22.0" }
4646
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
4747
ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version = "1.1.7" }
48+
jmh = { id = "me.champeau.jmh", version = "0.7.3" }
4849
kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.6" }
4950
ksp = { id = "com.google.devtools.ksp", version = "2.0.20-1.0.24" }
5051
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.5.0" }

selekt-java/build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ repositories {
2323

2424
plugins {
2525
kotlin("jvm")
26-
alias(libs.plugins.ksp)
2726
id("com.android.lint")
2827
alias(libs.plugins.kover)
2928
alias(libs.plugins.dokka)
3029
`maven-publish`
3130
signing
31+
alias(libs.plugins.jmh)
3232
alias(libs.plugins.detekt)
3333
alias(libs.plugins.ktlint)
3434
}
@@ -58,6 +58,13 @@ val integrationTestRuntimeOnly: Configuration by configurations.getting {
5858
dependencies {
5959
implementation(projects.selektApi)
6060
implementation(projects.selektSqlite3Classes)
61+
jmhImplementation(libs.kotlinx.coroutines.core)
62+
}
63+
64+
jmh {
65+
if (hasProperty("jmh.includes")) {
66+
includes.add(property("jmh.includes").toString())
67+
}
6168
}
6269

6370
publishing {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2024 Bloomberg Finance L.P.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bloomberg.selekt.cache.benchmarks;
18+
19+
import com.bloomberg.selekt.cache.LruCache;
20+
import org.jetbrains.annotations.NotNull;
21+
import org.openjdk.jmh.annotations.Benchmark;
22+
import org.openjdk.jmh.annotations.BenchmarkMode;
23+
import org.openjdk.jmh.annotations.Level;
24+
import org.openjdk.jmh.annotations.Mode;
25+
import org.openjdk.jmh.annotations.Scope;
26+
import org.openjdk.jmh.annotations.Setup;
27+
import org.openjdk.jmh.annotations.State;
28+
29+
public class LruCacheBenchmark {
30+
@State(Scope.Thread)
31+
public static class CacheInput {
32+
LruCache<Object> cache;
33+
34+
@Setup(Level.Iteration)
35+
public void setUp() {
36+
cache = new LruCache<>(1, obj -> kotlin.Unit.INSTANCE);
37+
}
38+
}
39+
@Benchmark
40+
@BenchmarkMode(Mode.Throughput)
41+
public Object getEntry(@NotNull final CacheInput input) {
42+
return input.cache.get("1", Object::new);
43+
}
44+
45+
@Benchmark
46+
@BenchmarkMode(Mode.Throughput)
47+
public Object getEntryWithEviction(@NotNull final CacheInput input) {
48+
input.cache.get("1", Object::new);
49+
return input.cache.get("2", Object::new);
50+
}
51+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020 Bloomberg Finance L.P.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bloomberg.selekt.pools.benchmarks;
18+
19+
import java.util.concurrent.Executors;
20+
import java.util.concurrent.ScheduledExecutorService;
21+
22+
public final class BenchmarkExecutors {
23+
private BenchmarkExecutors() {
24+
throw new AssertionError("Instantiation of the utility class " + BenchmarkExecutors.class.getName() +
25+
" is not allowed.");
26+
}
27+
28+
static final ScheduledExecutorService sharedExecutor = Executors.newSingleThreadScheduledExecutor(r -> {
29+
Thread thread = new Thread(r);
30+
thread.setDaemon(true);
31+
thread.setPriority(Thread.MIN_PRIORITY);
32+
return thread;
33+
});
34+
}

0 commit comments

Comments
 (0)