Skip to content

Commit

Permalink
Arrange benchmarks to avoid using unnecessary parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 authored and felldo committed Nov 16, 2023
1 parent d9df8f9 commit 6c4ad7e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
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
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());
}
}

0 comments on commit 6c4ad7e

Please sign in to comment.