Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
theigl committed Oct 16, 2023
2 parents 35c673d + e66d8a9 commit c2f63e7
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 55 deletions.
6 changes: 3 additions & 3 deletions benchmarks/pom.xml
Expand Up @@ -16,8 +16,8 @@

<properties>
<kryo.root>${basedir}/..</kryo.root>
<jmh.version>1.36</jmh.version>
<byte-buddy.version>1.14.4</byte-buddy.version>
<jmh.version>1.37</jmh.version>
<byte-buddy.version>1.14.9</byte-buddy.version>
<uberjar.name>benchmarks</uberjar.name>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down Expand Up @@ -51,7 +51,7 @@
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<executions>
<execution>
<id>build-classpath</id>
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/run.sh
@@ -1,10 +1,11 @@
#!/usr/bin/env bash

args="-f 4 -wi 5 -i 3 -t 2 -w 2s -r 2s -rf csv -rff"
jmh="$JAVA_HOME/bin/java -cp ../bin;../lib/*;lib/* com.esotericsoftware.kryo.benchmarks.KryoBenchmarks $args"
jmh="$JAVA_HOME/bin/java -cp ../eclipse/bin;../eclipse/.apt_generated;../lib/*;lib/* com.esotericsoftware.kryo.benchmarks.KryoBenchmarks $args"

set -ex

mkdir -p charts/results
$jmh charts/results/fieldSerializer.csv FieldSerializerBenchmark
$jmh charts/results/array.csv ArrayBenchmark
$jmh charts/results/string.csv StringBenchmark
Expand Down
@@ -0,0 +1,102 @@
package com.esotericsoftware.kryo.benchmarks;

import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.DefaultSerializers;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.math.BigDecimal;

import static java.lang.Integer.parseInt;
import static java.math.BigDecimal.ONE;
import static java.math.BigDecimal.ZERO;
import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static org.openjdk.jmh.runner.options.TimeValue.seconds;

public class BigDecimalBenchmark {

@State(Scope.Thread)
public static class MyState {
final Serializer<BigDecimal> serializer = new DefaultSerializers.BigDecimalSerializer();

Output output;
Input input;

@Param({
"null", "zero", "one", "0",
"2", "10", "max_in_long", "20", // twenty is more than the number of digits in Long.MAX_VALUE
"-2", "-10", "min_in_long", "-20" // twenty is more than the number of digits in Long.MIN_VALUE
})
String numOfDigits = "5";
int scale = 2;

BigDecimal decimal;

@Setup(Level.Iteration)
public void setUp() {
decimal = newDecimal(numOfDigits, scale);
output = new Output(2, -1);
serializer.write(null, output, decimal);
input = new Input(output.toBytes());
output.reset();
}

private static BigDecimal newDecimal(String numOfDigits, int scale) {
switch (numOfDigits) {
case "null": return null;
case "zero": return ZERO;
case "one": return ONE;
case "0": return BigDecimal.valueOf(0, scale);
case "max_in_long": return BigDecimal.valueOf(Long.MAX_VALUE, scale);
case "min_in_long": return BigDecimal.valueOf(Long.MIN_VALUE, scale);
default:
int digits = parseInt(numOfDigits.replace("-", ""));
BigDecimal d = BigDecimal.valueOf(10, 1 - digits).subtract(ONE).scaleByPowerOfTen(-scale); // '9' repeated numOfDigit times
return numOfDigits.charAt(0) != '-' ? d : d.negate();
}
}

@TearDown(Level.Iteration)
public void tearDown () {
output.close();
input.close();
}
}

@Benchmark
public byte[] write (MyState state) {
state.output.reset();
state.serializer.write(null, state.output, state.decimal);
return state.output.getBuffer();
}

@Benchmark
public BigDecimal read (MyState state) {
state.input.reset();
return state.serializer.read(null, state.input, BigDecimal.class);
}

public static void main (String[] args) throws RunnerException {
final Options opt = new OptionsBuilder()
.include(".*" + BigDecimalBenchmark.class.getSimpleName() + ".*")
.timeUnit(MICROSECONDS)
.warmupIterations(1)
.warmupTime(seconds(1))
.measurementIterations(4)
.measurementTime(seconds(1))
.forks(1)
.build();
new Runner(opt).run();
}
}
1 change: 1 addition & 0 deletions eclipse/.settings/org.eclipse.jdt.apt.core.prefs
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=.apt_generated
org.eclipse.jdt.apt.genTestSrcDir=.apt_generated_tests
org.eclipse.jdt.apt.reconcileEnabled=true
2 changes: 2 additions & 0 deletions eclipse/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=com.esotericsoftware.kryo.util.Null.NonNull
Expand Down Expand Up @@ -126,6 +127,7 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
Expand Down
28 changes: 14 additions & 14 deletions pom.xml
Expand Up @@ -51,8 +51,8 @@
<kryo.major.version>5</kryo.major.version>
<javac.target>1.8</javac.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.3</junit.version>
<kotlin.version>1.8.21</kotlin.version>
<junit.version>5.10.0</junit.version>
<kotlin.version>1.9.10</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>

Expand Down Expand Up @@ -85,7 +85,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>3.13.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -105,7 +105,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
</plugin>

<plugin>
Expand Down Expand Up @@ -146,7 +146,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.2</version>
</plugin>

<plugin>
Expand All @@ -168,7 +168,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<configuration>
<!-- Required for java8, so that javadoc errors don't fail the build. -->
<doclint>none</doclint>
Expand All @@ -186,7 +186,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
Expand All @@ -204,25 +204,25 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.8</version>
<version>5.1.9</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
</plugin>

<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.22.0</version>
<version>2.23.0</version>
<configuration>
<configFile>${kryo.root}/eclipse/code-format.xml</configFile>
<lineEnding>KEEP</lineEnding>
Expand Down Expand Up @@ -271,7 +271,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -284,7 +284,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -320,7 +320,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
<executions>
<execution>
<goals>
Expand Down

0 comments on commit c2f63e7

Please sign in to comment.