Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrange benchmarks to avoid using unnecessary parameters #19

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ testing {

jmh {
// includes.addAll("some regular expression") // include pattern (regular expression) for benchmarks to be executed
// excludes.addAll("some regular expression") // exclude pattern (regular expression) for benchmarks to be executed
excludes.addAll("excluded") // exclude pattern (regular expression) for benchmarks to be executed
// iterations.set(10) // Number of measurement iterations to do.
benchmarkMode.addAll("avgt") // Benchmark mode. Available modes are: [Throughput/thrpt, AverageTime/avgt, SampleTime/sample, SingleShotTime/ss, All/all]
// batchSize.set(1) // Batch size: number of benchmark method calls per operation. (some benchmark modes can ignore this setting)
Expand Down
22 changes: 22 additions & 0 deletions lib/src/jmh/java/benchmark/EmojiManagerAliasBenchmark.java
felldo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package benchmark;

import net.fellbaum.jemoji.Emoji;
import net.fellbaum.jemoji.EmojiManager;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

import java.util.Optional;

@State(Scope.Benchmark)
public class EmojiManagerAliasBenchmark {

@Param({":+1:", "nope"})
private String alias;

@Benchmark
public Optional<Emoji> getByAlias() {
return EmojiManager.getByAlias(alias);
}
}
17 changes: 4 additions & 13 deletions lib/src/jmh/java/benchmark/EmojiManagerBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import net.fellbaum.jemoji.EmojiManager;
import net.fellbaum.jemoji.EmojiManagerTest;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@State(Scope.Benchmark)
public class EmojiManagerBenchmark {

private static final String TEXT = new BufferedReader(new InputStreamReader(Objects.requireNonNull(EmojiManagerBenchmark.class.getClassLoader().getResourceAsStream("ExampleTextFileWithEmojis.txt"))))
Expand Down Expand Up @@ -42,14 +41,6 @@ public static void main(String[] args) throws Exception {

private static final String EMOJIS_RANDOM_ORDER = String.join("", EmojiManager.getAllEmojisLengthDescending().stream().map(Emoji::getEmoji).collect(toShuffledList()));

@Param({":+1:", "nope"})
private String alias;

@Benchmark
public Optional<Emoji> getByAlias() {
return EmojiManager.getByAlias(alias);
}

@Benchmark
//@BenchmarkMode(Mode.AverageTime)
//@Warmup(iterations = 1)
Expand Down
27 changes: 27 additions & 0 deletions lib/src/jmh/java/benchmark/excluded/CodePointBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package benchmark.excluded;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

@State(Scope.Benchmark)
public class CodePointBenchmark {
@Param("\uD83D\uDC4D\uD83C\uDFFC")
private String alias;

@Benchmark
public int codePointArrayLength() {
return alias.codePoints().toArray().length;
}

@Benchmark
public long codePointStreamCount() {
return alias.codePoints().count();
}

@Benchmark
public int codePointCount() {
return alias.codePointCount(0, alias.length());
}
}