Compare commits
1 Commits
main
...
unsafe_wri
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c8987d32d6 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1 +0,0 @@
|
||||
* text eol=lf
|
6
.github/workflows/ci.yaml
vendored
6
.github/workflows/ci.yaml
vendored
@ -18,8 +18,8 @@ jobs:
|
||||
timeout-minutes: 20
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-20.04, windows-latest, macos-latest ]
|
||||
java: [ 8, 11, 17, 21 ]
|
||||
os: [ ubuntu-20.04 ]
|
||||
java: [ 8, 11, 17 ]
|
||||
fail-fast: false
|
||||
max-parallel: 16
|
||||
name: Test on JDK ${{ matrix.java }} OS ${{ matrix.os }}
|
||||
@ -33,8 +33,6 @@ jobs:
|
||||
cache: maven
|
||||
- name: Build with Maven and generate code coverage
|
||||
run: ./mvnw -V --no-transfer-progress -Pgen-javadoc -Pgen-dokka clean package
|
||||
env:
|
||||
JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai
|
||||
# https://github.com/marketplace/actions/codecov
|
||||
- uses: codecov/codecov-action@v3
|
||||
with:
|
||||
|
BIN
.gitignore
vendored
BIN
.gitignore
vendored
Binary file not shown.
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
7
.mvn/wrapper/maven-wrapper.properties
vendored
7
.mvn/wrapper/maven-wrapper.properties
vendored
@ -6,7 +6,7 @@
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
@ -14,6 +14,5 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
|
||||
|
@ -2,9 +2,9 @@
|
||||
# Contributing
|
||||
|
||||
## Create pull request
|
||||
PR are always welcome, even if they only contain small fixes like typos, or a few lines of code. If there will be a significant effort, please document it as an issue and get a discussion going before starting to work on it.
|
||||
PR are always welcome, even if they only contain small fixes like typos or a few lines of code. If there will be a significant effort, please document it as an issue and get a discussion going before starting to work on it.
|
||||
|
||||
Please submit a PR broken down into small changes bit by bit. A PR consisting of a lot of features and code changes may be hard to review. It is recommended to submit PRs in an incremental fashion.
|
||||
Please submit a PR broken down into small changes bit by bit. A PR consisting of a lot features and code changes may be hard to review. It is recommended to submit PRs in an incremental fashion.
|
||||
|
||||
This [Wiki](https://github.com/alibaba/fastjson2/wiki) contains information about scenarios structure, design and api documents, how to use, how to run it, and more.
|
||||
|
||||
@ -22,6 +22,6 @@ When reporting issues, always include:
|
||||
* Steps to reproduce the issue.
|
||||
* Snapshots or log files if needed
|
||||
|
||||
Because the issues are open to the public, when submitting files, be sure to remove any sensitive information, e.g. username, password, IP address, and company name. You can
|
||||
Because the issues are open to the public, when submitting files, be sure to remove any sensitive information, e.g. user name, password, IP address, and company name. You can
|
||||
replace those parts with "REDACTED" or other strings like "****".
|
||||
|
||||
|
33
README.md
33
README.md
@ -41,7 +41,7 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.56'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.39-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
@ -67,7 +67,7 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -75,7 +75,7 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba:fastjson:2.0.56'
|
||||
implementation 'com.alibaba:fastjson:2.0.39-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
@ -89,13 +89,10 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-kotlin</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
酌情添加标准库(kotlin-stdlib)、反射库(kotlin-reflect),
|
||||
其中若使用数据类(data class)、通过构造函数传入参数则添加反射库。
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
@ -114,7 +111,7 @@ dependencies {
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.56")
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.39-SNAPSHOT")
|
||||
}
|
||||
```
|
||||
|
||||
@ -135,7 +132,7 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension-spring5</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -143,7 +140,7 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension-spring6</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -151,14 +148,14 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.56'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.39-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.56'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.39-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
@ -243,8 +240,8 @@ byte[] text = JSON.toJSONBytes(data);
|
||||
import com.alibaba.fastjson2.*
|
||||
|
||||
val data = ... // Any
|
||||
val text = data.toJSONString() // String
|
||||
val bytes = data.toJSONByteArray() // ByteArray
|
||||
val text = text.toJSONString() // String
|
||||
val bytes = text.toJSONByteArray() // ByteArray
|
||||
```
|
||||
|
||||
### 2.5 使用`JSONObject`、`JSONArray`
|
||||
@ -405,9 +402,3 @@ JSONPath path = JSONPath.of("$.id"); // 缓存起来重复使用能提升性能
|
||||
JSONReader parser = JSONReader.ofJSONB(bytes); // 注意这里使用ofJSONB方法
|
||||
Object result = path.extract(parser);
|
||||
```
|
||||
|
||||
## Star History
|
||||
|
||||
|
||||
[](https://star-history.com/#alibaba/fastjson2)
|
||||
|
||||
|
23
README_EN.md
23
README_EN.md
@ -47,7 +47,7 @@ Related Documents:
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -55,7 +55,7 @@ Related Documents:
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.56'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.39-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
@ -73,7 +73,7 @@ If you are using `fastjson 1.2.x`, you can use the compatibility package. The co
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -81,7 +81,7 @@ If you are using `fastjson 1.2.x`, you can use the compatibility package. The co
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba:fastjson:2.0.56'
|
||||
implementation 'com.alibaba:fastjson:2.0.39-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
@ -95,13 +95,10 @@ If your project uses `kotlin`, you can use the `Fastjson-Kotlin` module, and use
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-kotlin</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
Add standard library(kotlin-stdlib) and reflection library(kotlin-reflect) as appropriate.
|
||||
If the data class is used or the parameters are passed in through constructor, then add reflection library.
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
@ -120,7 +117,7 @@ If the data class is used or the parameters are passed in through constructor, t
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.56")
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.39-SNAPSHOT")
|
||||
}
|
||||
```
|
||||
|
||||
@ -141,7 +138,7 @@ If your project uses a framework such as `SpringFramework`, you can use the `fas
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension</artifactId>
|
||||
<version>2.0.56</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -149,7 +146,7 @@ If your project uses a framework such as `SpringFramework`, you can use the `fas
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.56'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.39-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
@ -234,8 +231,8 @@ byte[] text = JSON.toJSONBytes(data);
|
||||
import com.alibaba.fastjson2.*
|
||||
|
||||
val data = ... // Any
|
||||
val text = data.toJSONString() // String
|
||||
val bytes = data.toJSONByteArray() // ByteArray
|
||||
val text = text.toJSONString() // String
|
||||
val bytes = text.toJSONByteArray() // ByteArray
|
||||
```
|
||||
|
||||
### 2.5 Use `JSONObject`, `JSONArray`
|
||||
|
@ -39,11 +39,11 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation 'com.alibaba:fastjson:1.1.73.android'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.41-SNAPSHOT'
|
||||
implementation ('com.alibaba.fastjson2:fastjson2-codegen:2.0.40') {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.34.1.android4'
|
||||
implementation ('com.alibaba.fastjson2:fastjson2-codegen:2.0.34') {
|
||||
exclude group: 'com.alibaba.fastjson2', module: 'fastjson2'
|
||||
}
|
||||
implementation ('com.alibaba.fastjson2:fastjson2-kotlin:2.0.40') {
|
||||
implementation ('com.alibaba.fastjson2:fastjson2-kotlin:2.0.34') {
|
||||
exclude group: 'com.alibaba.fastjson2', module: 'fastjson2'
|
||||
}
|
||||
|
||||
|
@ -12,4 +12,4 @@ public class UnsafeTest {
|
||||
assertEquals("sun.misc.Unsafe", c.getCanonicalName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-parent</artifactId>
|
||||
<version>2.0.57-SNAPSHOT</version>
|
||||
<version>2.0.39-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -27,6 +27,13 @@
|
||||
<artifactId>fastjson2-extension</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-incubator-vector</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
@ -45,13 +52,13 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dslplatform</groupId>
|
||||
<artifactId>dsl-json</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<artifactId>dsl-json-java8</artifactId>
|
||||
<version>1.10.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<version>5.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
@ -86,15 +93,17 @@
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>io.fury</groupId>
|
||||
<artifactId>fury-core</artifactId>
|
||||
<version>0.11.2</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>io.github.wycst</groupId>
|
||||
<artifactId>wast</artifactId>
|
||||
<version>0.0.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>0.0.10.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.javacsv</groupId>
|
||||
@ -109,20 +118,15 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.fury</groupId>
|
||||
<artifactId>fury-core</artifactId>
|
||||
<version>0.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>jackson-dataformat-msgpack</artifactId>
|
||||
<version>0.9.9</version>
|
||||
<version>0.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>msgpack-core</artifactId>
|
||||
<version>0.9.8</version>
|
||||
<version>0.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
@ -131,7 +135,7 @@
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.7.1</version>
|
||||
<version>9.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
@ -205,4 +209,20 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>enable-incubators-for-jdk17+</id>
|
||||
<activation>
|
||||
<jdk>[17,)</jdk>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-incubator-vector</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.alibaba.fastjson2.benchmark;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.EishayParseBinaryArrayMapping;
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@ -12,53 +11,32 @@ import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.alibaba.fastjson2.util.JDKUtils.ARRAY_BYTE_BASE_OFFSET;
|
||||
import static com.alibaba.fastjson2.util.JDKUtils.UNSAFE;
|
||||
|
||||
public class BytesAsciiCheck {
|
||||
static byte[] bytes;
|
||||
static char[] chars;
|
||||
static String str;
|
||||
static final MethodHandle INDEX_OF_CHAR;
|
||||
|
||||
static {
|
||||
MethodHandle indexOfChar = null;
|
||||
try {
|
||||
try {
|
||||
Class<?> cStringLatin1 = Class.forName("java.lang.StringLatin1");
|
||||
MethodHandles.Lookup lookup = JDKUtils.trustedLookup(cStringLatin1);
|
||||
indexOfChar = lookup.findStatic(
|
||||
cStringLatin1,
|
||||
"indexOfChar",
|
||||
MethodType.methodType(int.class, byte[].class, int.class, int.class, int.class));
|
||||
} catch (Throwable ignored) {
|
||||
// ignore
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
INDEX_OF_CHAR = indexOfChar;
|
||||
try {
|
||||
InputStream is = EishayParseBinaryArrayMapping.class.getClassLoader().getResourceAsStream("data/eishay.json");
|
||||
str = IOUtils.toString(is, "UTF-8");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
bytes = str.getBytes();
|
||||
chars = str.toCharArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
@Benchmark
|
||||
public void handler(Blackhole bh) throws Throwable {
|
||||
bh.consume(
|
||||
JDKUtils.METHOD_HANDLE_HAS_NEGATIVE.invoke(bytes, 0, bytes.length)
|
||||
);
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
@Benchmark
|
||||
public void lambda(Blackhole bh) throws Throwable {
|
||||
bh.consume(
|
||||
JDKUtils.PREDICATE_IS_ASCII.test(bytes)
|
||||
@ -71,51 +49,13 @@ public class BytesAsciiCheck {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void isASCII(Blackhole bh) throws Throwable {
|
||||
bh.consume(com.alibaba.fastjson2.util.IOUtils.isASCII(bytes, 0, bytes.length));
|
||||
public void direct8(Blackhole bh) throws Throwable {
|
||||
bh.consume(hasNegatives_8(bytes, 0, bytes.length));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void isNonSlashASCII(Blackhole bh) throws Throwable {
|
||||
bh.consume(com.alibaba.fastjson2.util.IOUtils.isNonSlashASCII(bytes, 0, bytes.length));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void isLatin1(Blackhole bh) throws Throwable {
|
||||
bh.consume(com.alibaba.fastjson2.util.IOUtils.isLatin1(chars, 0, chars.length));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void isASCIIJDK(Blackhole bh) throws Throwable {
|
||||
bh.consume(com.alibaba.fastjson2.util.JDKUtils.PREDICATE_IS_ASCII.test(bytes));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void indexOfSlash(Blackhole bh) throws Throwable {
|
||||
bh.consume(com.alibaba.fastjson2.util.IOUtils.indexOfSlash(bytes, 0, bytes.length));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void indexOfSlashV(Blackhole bh) throws Throwable {
|
||||
bh.consume(com.alibaba.fastjson2.util.IOUtils.indexOfSlashV(bytes, 0, bytes.length));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void indexOfChar(Blackhole bh) throws Throwable {
|
||||
bh.consume(indexOfChar(bytes, '\'', 0, bytes.length));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void indexOfString(Blackhole bh) throws Throwable {
|
||||
bh.consume(str.indexOf('\\'));
|
||||
}
|
||||
|
||||
private static int indexOfChar(byte[] bytes, int ch, int fromIndex, int toIndex) {
|
||||
try {
|
||||
return (int) INDEX_OF_CHAR.invokeExact(bytes, ch, fromIndex, toIndex);
|
||||
} catch (Throwable ignored) {
|
||||
throw new JSONException("");
|
||||
}
|
||||
public void direct8u(Blackhole bh) throws Throwable {
|
||||
bh.consume(hasNegatives_8u(bytes, 0, bytes.length));
|
||||
}
|
||||
|
||||
public static boolean hasNegatives(byte[] ba, int off, int len) {
|
||||
@ -127,13 +67,54 @@ public class BytesAsciiCheck {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasNegatives_8(byte[] bytes, int off, int len) {
|
||||
int i = off;
|
||||
while (i + 8 <= off + len) {
|
||||
byte b0 = bytes[0];
|
||||
byte b1 = bytes[1];
|
||||
byte b2 = bytes[2];
|
||||
byte b3 = bytes[3];
|
||||
byte b4 = bytes[4];
|
||||
byte b5 = bytes[5];
|
||||
byte b6 = bytes[6];
|
||||
byte b7 = bytes[6];
|
||||
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0 || b4 < 0 || b5 < 0 || b6 < 0 || b7 < 0) {
|
||||
return true;
|
||||
}
|
||||
i += 8;
|
||||
}
|
||||
|
||||
for (; i < off + len; i++) {
|
||||
if (bytes[i] < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasNegatives_8u(byte[] bytes, int off, int len) {
|
||||
int i = off;
|
||||
while (i + 8 <= off + len) {
|
||||
if ((UNSAFE.getLong(bytes, ARRAY_BYTE_BASE_OFFSET + off) & 0x8080808080808080L) != 0) {
|
||||
return true;
|
||||
}
|
||||
i += 8;
|
||||
}
|
||||
|
||||
for (; i < off + len; i++) {
|
||||
if (bytes[i] < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(BytesAsciiCheck.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
.threads(16)
|
||||
.forks(1)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
|
@ -15,32 +15,28 @@ import java.util.concurrent.TimeUnit;
|
||||
@Measurement(iterations = 1000, time = 5)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
public class CartItemDO2Benchmark {
|
||||
private static volatile List<CartItemDO2> list; // 使用 volatile 修饰确保可见性
|
||||
static List<CartItemDO2> list;
|
||||
|
||||
private static List<CartItemDO2> newCartsItem() {
|
||||
if (list != null) {
|
||||
return list;
|
||||
}
|
||||
|
||||
synchronized (CartItemDO2Benchmark.class) {
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
for (long i = 90000000000L; i < 90000000000L + 1000; i++) {
|
||||
CartItemDO2 cartItemDO2 = new CartItemDO2();
|
||||
cartItemDO2.setUserId(i);
|
||||
cartItemDO2.setAttributes(new HashMap<>());
|
||||
cartItemDO2.setCartId(i * 100);
|
||||
cartItemDO2.setCityCode(i * 12);
|
||||
cartItemDO2.setItemId(i * 3);
|
||||
cartItemDO2.setMainType(11);
|
||||
cartItemDO2.setQuantity(900);
|
||||
cartItemDO2.setSkuId(i * 5);
|
||||
cartItemDO2.setSubType(i * 6);
|
||||
cartItemDO2.setTpId(i * 7);
|
||||
cartItemDO2.setTrackId(String.valueOf(i * 8));
|
||||
list.add(cartItemDO2);
|
||||
}
|
||||
}
|
||||
list = new ArrayList<>();
|
||||
for (long i = 90000000000L; i < 90000000000L + 1000; i++) {
|
||||
CartItemDO2 cartItemDO2 = new CartItemDO2();
|
||||
cartItemDO2.setUserId(i);
|
||||
cartItemDO2.setAttributes(new HashMap<>());
|
||||
cartItemDO2.setCartId(i * 100);
|
||||
cartItemDO2.setCityCode(i * 12);
|
||||
cartItemDO2.setItemId(i * 3);
|
||||
cartItemDO2.setMainType(11);
|
||||
cartItemDO2.setQuantity(900);
|
||||
cartItemDO2.setSkuId(i * 5);
|
||||
cartItemDO2.setSubType(i * 6);
|
||||
cartItemDO2.setTpId(i * 7);
|
||||
cartItemDO2.setTrackId(String.valueOf(i * 8));
|
||||
list.add(cartItemDO2);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class DateWrite {
|
||||
static String formatYYYYMMDDHHMMSS19(ZoneId zoneId, Date date) throws Throwable {
|
||||
long millis = date.getTime();
|
||||
|
||||
final long SECONDS_PER_DAY = 60 * 60 * 24;
|
||||
final int SECONDS_PER_DAY = 60 * 60 * 24;
|
||||
|
||||
long epochSecond = Math.floorDiv(millis, 1000L);
|
||||
int offsetTotalSeconds;
|
||||
@ -90,8 +90,8 @@ public class DateWrite {
|
||||
}
|
||||
|
||||
long localSecond = epochSecond + offsetTotalSeconds;
|
||||
long localEpochDay = Math.floorDiv(localSecond, SECONDS_PER_DAY);
|
||||
int secsOfDay = (int) Math.floorMod(localSecond, SECONDS_PER_DAY);
|
||||
long localEpochDay = Math.floorDiv(localSecond, (long) SECONDS_PER_DAY);
|
||||
int secsOfDay = (int) Math.floorMod(localSecond, (long) SECONDS_PER_DAY);
|
||||
int year, month, dayOfMonth;
|
||||
{
|
||||
final int DAYS_PER_CYCLE = 146097;
|
||||
|
@ -37,11 +37,11 @@ public class LambdaGenerator {
|
||||
"()V",
|
||||
64
|
||||
);
|
||||
mw.aload(THIS);
|
||||
mw.visitVarInsn(Opcodes.ALOAD, THIS);
|
||||
|
||||
mw.invokespecial("java/lang/Object", "<init>", "()V");
|
||||
mw.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
|
||||
|
||||
mw.return_();
|
||||
mw.visitInsn(Opcodes.RETURN);
|
||||
mw.visitMaxs(3, 3);
|
||||
}
|
||||
|
||||
@ -54,9 +54,9 @@ public class LambdaGenerator {
|
||||
|
||||
String TYPE_OBJECT = ASMUtils.type(objectClass);
|
||||
int OBJECT = 1, VALUE = 2;
|
||||
mw.aload(OBJECT);
|
||||
mw.checkcast(TYPE_OBJECT);
|
||||
mw.iload(VALUE);
|
||||
mw.visitVarInsn(Opcodes.ALOAD, OBJECT);
|
||||
mw.visitTypeInsn(Opcodes.CHECKCAST, TYPE_OBJECT);
|
||||
mw.visitVarInsn(Opcodes.ILOAD, VALUE);
|
||||
|
||||
Class returnType = Void.TYPE;
|
||||
String methodDesc;
|
||||
@ -66,12 +66,12 @@ public class LambdaGenerator {
|
||||
methodDesc = "(I)" + ASMUtils.desc(returnType);
|
||||
}
|
||||
|
||||
mw.invokevirtual(TYPE_OBJECT, methodName, methodDesc);
|
||||
mw.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TYPE_OBJECT, methodName, methodDesc, false);
|
||||
if (returnType != Void.TYPE) {
|
||||
mw.pop();
|
||||
mw.visitInsn(Opcodes.POP);
|
||||
}
|
||||
|
||||
mw.return_();
|
||||
mw.visitInsn(Opcodes.RETURN);
|
||||
mw.visitMaxs(2, 2);
|
||||
|
||||
byte[] code = cw.toByteArray();
|
||||
|
@ -7,7 +7,6 @@ import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.zip.ZipInputStream;
|
||||
@ -26,8 +25,7 @@ public class LargeFile2MTest {
|
||||
) {
|
||||
zipIn.getNextEntry();
|
||||
str = IOUtils.toString(zipIn, "UTF-8");
|
||||
zipIn.closeEntry();
|
||||
} catch (IOException ex) {
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -47,34 +45,60 @@ public class LargeFile2MTest {
|
||||
bh.consume(mapper.readValue(str, HashMap.class));
|
||||
}
|
||||
|
||||
public void perfTest(Runnable task) {
|
||||
// @Test
|
||||
public void fastjson1_perf_test() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
fastjson1_perf();
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void fastjson2_perf_test() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
fastjson2_perf();
|
||||
}
|
||||
}
|
||||
|
||||
public void jackson_perf_test() throws Exception {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
jackson_perf();
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastjson2_perf() {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
task.run();
|
||||
JSON.parseObject(str);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("millis : " + millis);
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu17.32.13 : 1299 1136
|
||||
// zulu11.52.13 : 1187 1145
|
||||
// zulu8.58.0.13 : 1154
|
||||
}
|
||||
|
||||
public void fastjson1_perf_test() {
|
||||
perfTest(() -> com.alibaba.fastjson.JSON.parseObject(str));
|
||||
public static void jackson_perf() throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
mapper.readValue(str, HashMap.class);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("jackson millis : " + millis);
|
||||
// zulu17.32.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu8.58.0.13 :
|
||||
}
|
||||
|
||||
public void fastjson2_perf_test() {
|
||||
perfTest(() -> JSON.parseObject(str));
|
||||
}
|
||||
|
||||
public void jackson_perf_test() throws Exception {
|
||||
perfTest(() -> {
|
||||
try {
|
||||
mapper.readValue(str, HashMap.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
public static void fastjson1_perf() {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
com.alibaba.fastjson.JSON.parseObject(str);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson1 millis : " + millis);
|
||||
// zulu17.32.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu8.58.0.13 :
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -1,76 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.EishayParseTreeString;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.EishayParseTreeStringPretty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
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.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Name8 {
|
||||
static String str;
|
||||
static final ObjectMapper mapper = new ObjectMapper();
|
||||
static final Gson gson = new Gson();
|
||||
|
||||
static {
|
||||
try {
|
||||
InputStream is = EishayParseTreeString.class.getClassLoader().getResourceAsStream("data/name8.json");
|
||||
str = IOUtils.toString(is, "UTF-8");
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson1(Blackhole bh) {
|
||||
bh.consume(com.alibaba.fastjson.JSON.parseObject(str));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(str));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jackson(Blackhole bh) throws Exception {
|
||||
bh.consume(mapper.readValue(str, HashMap.class));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void wastjson(Blackhole bh) throws Exception {
|
||||
bh.consume(
|
||||
io.github.wycst.wast.json.JSON.parse(str)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void gson(Blackhole bh) throws Exception {
|
||||
bh.consume(
|
||||
gson.fromJson(str, HashMap.class)
|
||||
);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(EishayParseTreeString.class.getName())
|
||||
.exclude(EishayParseTreeStringPretty.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
.forks(1)
|
||||
.threads(16)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
@ -3,13 +3,8 @@ package com.alibaba.fastjson2.benchmark.along;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.benchmark.along.vo.HarmDTO;
|
||||
import com.alibaba.fastjson2.benchmark.along.vo.SkillCategory;
|
||||
import com.alibaba.fastjson2.benchmark.along.vo.SkillFire_S2C_Msg;
|
||||
import com.alibaba.fastjson2.reader.ObjectReaderProvider;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.fury.Fury;
|
||||
import org.apache.fury.config.Language;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
@ -24,37 +19,15 @@ import static com.alibaba.fastjson2.JSONReader.Feature.FieldBased;
|
||||
import static com.alibaba.fastjson2.JSONReader.Feature.SupportArrayToBean;
|
||||
|
||||
public class AlongParseBinaryArrayMapping {
|
||||
static final ObjectReaderProvider providerFeatures = new ObjectReaderProvider();
|
||||
static final JSONReader.Context contextFeatures;
|
||||
|
||||
static Fury fury;
|
||||
|
||||
static SkillFire_S2C_Msg object;
|
||||
static SkillFire_S2C_Msg mc;
|
||||
static byte[] fastjson2JSONBBytes;
|
||||
static byte[] furyBytes;
|
||||
|
||||
static {
|
||||
providerFeatures.setDisableAutoType(true);
|
||||
providerFeatures.setDisableReferenceDetect(true);
|
||||
contextFeatures = new JSONReader.Context(providerFeatures, JSONReader.Feature.SupportArrayToBean, JSONReader.Feature.FieldBased);
|
||||
|
||||
try {
|
||||
InputStream is = AlongParseBinaryArrayMapping.class.getClassLoader().getResourceAsStream("data/along.json");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
object = JSONReader.of(str, contextFeatures).read(SkillFire_S2C_Msg.class);
|
||||
|
||||
fury = Fury.builder().withLanguage(Language.JAVA)
|
||||
.withRefTracking(false)
|
||||
.requireClassRegistration(false)
|
||||
.withNumberCompressed(true)
|
||||
.build();
|
||||
|
||||
fury.register(SkillCategory.class);
|
||||
fury.register(SkillFire_S2C_Msg.class);
|
||||
fury.register(HarmDTO.class);
|
||||
|
||||
fastjson2JSONBBytes = JSONB.toBytes(object, JSONWriter.Feature.BeanToArray);
|
||||
furyBytes = fury.serializeJavaObject(object);
|
||||
mc = JSONReader.of(str).read(SkillFire_S2C_Msg.class);
|
||||
fastjson2JSONBBytes = JSONB.toBytes(mc, JSONWriter.Feature.BeanToArray);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -62,17 +35,7 @@ public class AlongParseBinaryArrayMapping {
|
||||
|
||||
@Benchmark
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(JSONB.parseObject(fastjson2JSONBBytes, SkillFire_S2C_Msg.class, FieldBased, SupportArrayToBean));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jsonbFeatures(Blackhole bh) {
|
||||
bh.consume(JSONB.parseObject(fastjson2JSONBBytes, SkillFire_S2C_Msg.class, contextFeatures));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
bh.consume(fury.deserializeJavaObject(furyBytes, SkillFire_S2C_Msg.class));
|
||||
bh.consume(JSONB.parseObject(fastjson2JSONBBytes, SkillFire_S2C_Msg.class, SupportArrayToBean, FieldBased));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -5,10 +5,7 @@ import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.benchmark.along.vo.SkillFire_S2C_Msg;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.fury.Fury;
|
||||
import org.apache.fury.config.Language;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
@ -21,64 +18,31 @@ import java.io.InputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AlongWriteBinaryArrayMapping {
|
||||
static final ObjectWriterProvider providerFeatures = new ObjectWriterProvider();
|
||||
static final JSONWriter.Context contextFeatures;
|
||||
static SkillFire_S2C_Msg object;
|
||||
static Fury fury;
|
||||
static SkillFire_S2C_Msg mc;
|
||||
|
||||
static {
|
||||
try {
|
||||
InputStream is = AlongWriteBinaryArrayMapping.class.getClassLoader().getResourceAsStream("data/along.json");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
object = JSONReader.of(str)
|
||||
mc = JSONReader.of(str)
|
||||
.read(SkillFire_S2C_Msg.class);
|
||||
|
||||
fury = Fury.builder()
|
||||
.withLanguage(Language.JAVA)
|
||||
.withRefTracking(false)
|
||||
.requireClassRegistration(false)
|
||||
.withNumberCompressed(true)
|
||||
.build();
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
providerFeatures.setDisableAutoType(true);
|
||||
providerFeatures.setDisableReferenceDetect(true);
|
||||
contextFeatures = new JSONWriter.Context(providerFeatures, JSONWriter.Feature.BeanToArray, JSONWriter.Feature.FieldBased);
|
||||
}
|
||||
|
||||
public int jsonbSize() {
|
||||
return JSONB.toBytes(object, JSONWriter.Feature.BeanToArray).length;
|
||||
return JSONB.toBytes(mc, JSONWriter.Feature.BeanToArray).length;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(JSONB.toBytes(object, JSONWriter.Feature.BeanToArray, JSONWriter.Feature.FieldBased));
|
||||
bh.consume(JSONB.toBytes(mc, JSONWriter.Feature.BeanToArray, JSONWriter.Feature.FieldBased));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jsonbFeatures(Blackhole bh) {
|
||||
bh.consume(JSONB.toBytes(object, contextFeatures));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
bh.consume(fury.serialize(object));
|
||||
}
|
||||
|
||||
public int furySize() {
|
||||
return fury.serialize(object).length;
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void json(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONBytes(object, JSONWriter.Feature.BeanToArray, JSONWriter.Feature.FieldBased));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void jsonStr(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONString(object, JSONWriter.Feature.BeanToArray, JSONWriter.Feature.FieldBased));
|
||||
bh.consume(JSON.toJSONBytes(mc, JSONWriter.Feature.BeanToArray, JSONWriter.Feature.FieldBased));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
@ -12,13 +12,10 @@ public class Eishay {
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(Eishay.class.getName())
|
||||
.include(EishayFuryCompatibleParse.class.getName())
|
||||
.include(EishayFuryCompatibleWrite.class.getName())
|
||||
.exclude(EishayParseStringNoneCache.class.getName())
|
||||
.exclude(EishayWriteStringNoneCache.class.getName())
|
||||
.exclude(EishayWriteStringTree1x.class.getName())
|
||||
.exclude(EishayFuryParse.class.getName())
|
||||
.exclude(EishayFuryWrite.class.getName())
|
||||
.exclude(EishayFury.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
|
@ -31,13 +31,13 @@ public class EishayFuryCompatibleParse {
|
||||
|
||||
static byte[] jsonbBytes;
|
||||
static byte[] furyCompatibleBytes;
|
||||
|
||||
static org.apache.fury.ThreadSafeFury furyCompatible = org.apache.fury.Fury.builder()
|
||||
.withLanguage(org.apache.fury.config.Language.JAVA)
|
||||
.withRefTracking(true)
|
||||
.requireClassRegistration(false)
|
||||
.withCompatibleMode(org.apache.fury.config.CompatibleMode.COMPATIBLE)
|
||||
.buildThreadSafeFury();
|
||||
//
|
||||
// static io.fury.ThreadSafeFury furyCompatible = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .withCompatibleMode(io.fury.serializers.CompatibleMode.COMPATIBLE)
|
||||
// .buildThreadSafeFury();
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -47,7 +47,7 @@ public class EishayFuryCompatibleParse {
|
||||
.read(MediaContent.class);
|
||||
|
||||
jsonbBytes = JSONB.toBytes(mc, EishayFuryCompatibleWrite.features);
|
||||
furyCompatibleBytes = furyCompatible.serialize(mc);
|
||||
// furyCompatibleBytes = furyCompatible.serialize(mc);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -59,10 +59,10 @@ public class EishayFuryCompatibleParse {
|
||||
bh.consume(object);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
Object object = furyCompatible.deserialize(furyCompatibleBytes);
|
||||
bh.consume(object);
|
||||
// Object object = furyCompatible.deserialize(furyCompatibleBytes);
|
||||
// bh.consume(object);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -3,8 +3,6 @@ package com.alibaba.fastjson2.benchmark.eishay;
|
||||
import com.alibaba.fastjson2.*;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.vo.MediaContent;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.fury.Fury;
|
||||
import org.apache.fury.ThreadSafeFury;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
@ -26,18 +24,19 @@ public class EishayFuryCompatibleWrite {
|
||||
JSONWriter.Feature.ReferenceDetection,
|
||||
JSONWriter.Feature.WriteNulls,
|
||||
JSONWriter.Feature.NotWriteDefaultValue,
|
||||
JSONWriter.Feature.WriteNameAsSymbol,
|
||||
JSONWriter.Feature.NotWriteHashMapArrayListClassName
|
||||
};
|
||||
static JSONWriter.Context context = new JSONWriter.Context(
|
||||
JSONFactory.getDefaultObjectWriterProvider(), features
|
||||
);
|
||||
|
||||
static ThreadSafeFury furyCompatible = Fury.builder()
|
||||
.withLanguage(org.apache.fury.config.Language.JAVA)
|
||||
.withRefTracking(true)
|
||||
.requireClassRegistration(false)
|
||||
.withCompatibleMode(org.apache.fury.config.CompatibleMode.COMPATIBLE)
|
||||
.buildThreadSafeFury();
|
||||
//
|
||||
// static io.fury.ThreadSafeFury furyCompatible = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .withCompatibleMode(io.fury.serializers.CompatibleMode.COMPATIBLE)
|
||||
// .buildThreadSafeFury();
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -60,15 +59,15 @@ public class EishayFuryCompatibleWrite {
|
||||
return JSONB.toBytes(mc, context).length;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
byte[] bytes = furyCompatible.serialize(mc);
|
||||
bh.consume(bytes);
|
||||
// byte[] bytes = furyCompatible.serialize(mc);
|
||||
// bh.consume(bytes);
|
||||
}
|
||||
|
||||
public int furySize() {
|
||||
return furyCompatible.serialize(mc).length;
|
||||
// return 0;
|
||||
// return furyCompatible.serialize(mc).length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
@ -27,12 +27,12 @@ public class EishayFuryParse {
|
||||
|
||||
static byte[] jsonbBytes;
|
||||
static byte[] furyBytes;
|
||||
|
||||
static org.apache.fury.ThreadSafeFury fury = org.apache.fury.Fury.builder()
|
||||
.withLanguage(org.apache.fury.config.Language.JAVA)
|
||||
.requireClassRegistration(false)
|
||||
.withRefTracking(true)
|
||||
.buildThreadSafeFury();
|
||||
//
|
||||
// static io.fury.ThreadSafeFury fury = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .buildThreadSafeFury();
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -46,7 +46,7 @@ public class EishayFuryParse {
|
||||
EishayFuryWrite.features
|
||||
);
|
||||
|
||||
furyBytes = fury.serializeJavaObject(mc);
|
||||
// furyBytes = fury.serialize(mc);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -58,10 +58,10 @@ public class EishayFuryParse {
|
||||
bh.consume(object);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
Object object = fury.deserialize(furyBytes);
|
||||
bh.consume(object);
|
||||
// Object object = fury.deserialize(furyBytes);
|
||||
// bh.consume(object);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -35,12 +35,13 @@ public class EishayFuryParseNoneCache {
|
||||
static byte[][] fastjson2JSONBBytes = new byte[COUNT][];
|
||||
static byte[][] furyBytes = new byte[COUNT][];
|
||||
static int index;
|
||||
|
||||
static org.apache.fury.ThreadSafeFury fury = org.apache.fury.Fury.builder()
|
||||
.withLanguage(org.apache.fury.config.Language.JAVA)
|
||||
.withRefTracking(true)
|
||||
.withClassLoader(classLoader)
|
||||
.buildThreadSafeFury();
|
||||
//
|
||||
// static io.fury.ThreadSafeFury fury = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .withClassLoader(classLoader)
|
||||
// .buildThreadSafeFury();
|
||||
|
||||
static {
|
||||
String classZipDataFile = "data/EishayFuryParseNoneCache_classes.bin.zip";
|
||||
@ -114,11 +115,11 @@ public class EishayFuryParseNoneCache {
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
byte[] bytes = furyBytes[index++];
|
||||
bh.consume(fury.deserialize(bytes));
|
||||
// bh.consume(fury.deserialize(bytes));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -19,12 +19,12 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EishayFuryWrite {
|
||||
static MediaContent object;
|
||||
|
||||
static org.apache.fury.ThreadSafeFury fury = org.apache.fury.Fury.builder()
|
||||
.withLanguage(org.apache.fury.config.Language.JAVA)
|
||||
.requireClassRegistration(false)
|
||||
.withRefTracking(true)
|
||||
.buildThreadSafeFury();
|
||||
//
|
||||
// static io.fury.ThreadSafeFury fury = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .buildThreadSafeFury();
|
||||
|
||||
static JSONWriter.Feature[] features = {
|
||||
JSONWriter.Feature.WriteClassName,
|
||||
@ -57,10 +57,10 @@ public class EishayFuryWrite {
|
||||
bh.consume(bytes);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
byte[] bytes = fury.serialize(object);
|
||||
bh.consume(bytes);
|
||||
// byte[] bytes = fury.serialize(object);
|
||||
// bh.consume(bytes);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
@ -23,10 +23,11 @@ public class EishayFuryWriteNoneCache {
|
||||
static final Object[] objects = new Object[classes.length];
|
||||
static int index;
|
||||
|
||||
static org.apache.fury.ThreadSafeFury fury = org.apache.fury.Fury.builder()
|
||||
.withLanguage(org.apache.fury.config.Language.JAVA)
|
||||
.withRefTracking(true)
|
||||
.buildThreadSafeFury();
|
||||
// static io.fury.ThreadSafeFury fury = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .buildThreadSafeFury();
|
||||
|
||||
static JSONWriter.Feature[] features = {
|
||||
JSONWriter.Feature.WriteClassName,
|
||||
@ -67,11 +68,11 @@ public class EishayFuryWriteNoneCache {
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
Object object = objects[(index++) % objects.length];
|
||||
byte[] bytes = fury.serialize(object);
|
||||
bh.consume(bytes);
|
||||
// Object object = objects[(index++) % objects.length];
|
||||
// byte[] bytes = fury.serialize(object);
|
||||
// bh.consume(bytes);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
@ -98,16 +98,6 @@ public class EishayParseBinary {
|
||||
);
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void jsonbValid(Blackhole bh) {
|
||||
JSONReader jsonReader = JSONReader.ofJSONB(fastjson2JSONBBytes);
|
||||
jsonReader.skipValue();
|
||||
bh.consume(
|
||||
jsonReader.isEnd()
|
||||
);
|
||||
jsonReader.close();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void javaSerialize(Blackhole bh) throws Exception {
|
||||
ByteArrayInputStream bytesIn = new ByteArrayInputStream(javaSerializeBytes);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.alibaba.fastjson2.benchmark.eishay;
|
||||
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
@ -12,8 +14,6 @@ import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.io.Input;
|
||||
import com.esotericsoftware.kryo.io.Output;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.fury.Fury;
|
||||
import org.apache.fury.config.Language;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
@ -26,38 +26,35 @@ import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EishayParseBinaryArrayMapping {
|
||||
static final Fury fury = Fury.builder().withLanguage(Language.JAVA)
|
||||
.withRefTracking(false)
|
||||
.requireClassRegistration(false)
|
||||
.withNumberCompressed(true)
|
||||
.build();
|
||||
|
||||
static MediaContent mediaContent;
|
||||
static MediaContent mc;
|
||||
static byte[] fastjson2UTF8Bytes;
|
||||
static byte[] fastjson2JSONBBytes;
|
||||
static byte[] kryoBytes;
|
||||
|
||||
static byte[] protobufBytes;
|
||||
static byte[] furyBytes;
|
||||
|
||||
private static final ThreadLocal<Kryo> kryos = ThreadLocal.withInitial(() -> {
|
||||
Kryo kryo = new Kryo();
|
||||
kryo.register(MediaContent.class);
|
||||
kryo.register(ArrayList.class);
|
||||
kryo.register(Image.class);
|
||||
kryo.register(Image.Size.class);
|
||||
kryo.register(Media.class);
|
||||
kryo.register(Media.Player.class);
|
||||
return kryo;
|
||||
});
|
||||
private static final ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
|
||||
protected Kryo initialValue() {
|
||||
Kryo kryo = new Kryo();
|
||||
kryo.register(MediaContent.class);
|
||||
kryo.register(ArrayList.class);
|
||||
kryo.register(Image.class);
|
||||
kryo.register(Image.Size.class);
|
||||
kryo.register(Media.class);
|
||||
kryo.register(Media.Player.class);
|
||||
return kryo;
|
||||
}
|
||||
};
|
||||
|
||||
static {
|
||||
try {
|
||||
InputStream is = EishayParseBinaryArrayMapping.class.getClassLoader().getResourceAsStream("data/eishay.json");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
mediaContent = JSONReader.of(str)
|
||||
mc = JSONReader.of(str)
|
||||
.read(MediaContent.class);
|
||||
|
||||
fastjson2JSONBBytes = JSONB.toBytes(mediaContent, JSONWriter.Feature.BeanToArray);
|
||||
fastjson2UTF8Bytes = JSON.toJSONBytes(mc, JSONWriter.Feature.BeanToArray);
|
||||
fastjson2JSONBBytes = JSONB.toBytes(mc, JSONWriter.Feature.BeanToArray);
|
||||
|
||||
Kryo kryo = new Kryo();
|
||||
kryo.register(MediaContent.class);
|
||||
@ -68,28 +65,28 @@ public class EishayParseBinaryArrayMapping {
|
||||
kryo.register(Media.Player.class);
|
||||
|
||||
Output output = new Output(1024, -1);
|
||||
kryo.writeObject(output, mediaContent);
|
||||
kryo.writeObject(output, mc);
|
||||
kryoBytes = output.toBytes();
|
||||
|
||||
protobufBytes = MediaContentTransform.forward(mediaContent).toByteArray();
|
||||
furyBytes = MediaContentTransform.forward(mediaContent).toByteArray();
|
||||
protobufBytes = MediaContentTransform.forward(mc).toByteArray();
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
bh.consume(
|
||||
fury.deserializeJavaObject(furyBytes, MediaContent.class)
|
||||
);
|
||||
public void fastjson1UTF8Bytes(Blackhole bh) {
|
||||
bh.consume(com.alibaba.fastjson.JSON.parseObject(fastjson2UTF8Bytes, MediaContent.class, Feature.SupportArrayToBean));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2UTF8Bytes(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(fastjson2UTF8Bytes, MediaContent.class, JSONReader.Feature.SupportArrayToBean));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSONB.parseObject(fastjson2JSONBBytes, MediaContent.class, JSONReader.Feature.SupportArrayToBean)
|
||||
);
|
||||
bh.consume(JSONB.parseObject(fastjson2JSONBBytes, MediaContent.class, JSONReader.Feature.SupportArrayToBean));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.alibaba.fastjson2.benchmark.eishay;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.vo.MediaContent;
|
||||
import com.alibaba.fastjson2.reader.ObjectReaderProvider;
|
||||
import com.dslplatform.json.DslJson;
|
||||
import com.dslplatform.json.runtime.Settings;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -27,16 +25,7 @@ public class EishayParseUTF8Bytes {
|
||||
static final ObjectMapper mapper = new ObjectMapper();
|
||||
static final Gson gson = new Gson();
|
||||
static final DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().includeServiceLoader());
|
||||
static final ObjectReaderProvider featuresProvider;
|
||||
static final JSONReader.Context featuresContext;
|
||||
static {
|
||||
ObjectReaderProvider provider = new ObjectReaderProvider();
|
||||
provider.setDisableReferenceDetect(true);
|
||||
provider.setDisableJSONB(true);
|
||||
provider.setDisableArrayMapping(true);
|
||||
provider.setDisableAutoType(true);
|
||||
featuresProvider = provider;
|
||||
featuresContext = new JSONReader.Context(provider);
|
||||
try {
|
||||
InputStream is = EishayParseUTF8Bytes.class.getClassLoader().getResourceAsStream("data/eishay_compact.json");
|
||||
utf8Bytes = IOUtils.toString(is, "UTF-8").getBytes(StandardCharsets.UTF_8);
|
||||
@ -56,15 +45,6 @@ public class EishayParseUTF8Bytes {
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void fastjson2_charset(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(utf8Bytes, 0, utf8Bytes.length, StandardCharsets.ISO_8859_1, MediaContent.class));
|
||||
}
|
||||
|
||||
public void fastjson2_features(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(utf8Bytes, MediaContent.class, featuresContext));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void dsljson(Blackhole bh) throws IOException {
|
||||
bh.consume(dslJson.deserialize(MediaContent.class, utf8Bytes, utf8Bytes.length));
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.alibaba.fastjson2.benchmark.eishay;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
@ -10,8 +12,6 @@ import com.alibaba.fastjson2.benchmark.protobuf.MediaContentTransform;
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.io.Output;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.fury.Fury;
|
||||
import org.apache.fury.config.Language;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
@ -25,13 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EishayWriteBinaryArrayMapping {
|
||||
static final Fury fury = Fury.builder().withLanguage(Language.JAVA)
|
||||
.withRefTracking(false)
|
||||
.requireClassRegistration(false)
|
||||
.withNumberCompressed(true)
|
||||
.build();
|
||||
|
||||
static MediaContent mediaContent;
|
||||
static MediaContent mc;
|
||||
private static final ThreadLocal<Kryo> kryos = ThreadLocal.withInitial(() -> {
|
||||
Kryo kryo = new Kryo();
|
||||
kryo.register(MediaContent.class);
|
||||
@ -49,7 +43,7 @@ public class EishayWriteBinaryArrayMapping {
|
||||
try {
|
||||
InputStream is = EishayWriteBinaryArrayMapping.class.getClassLoader().getResourceAsStream("data/eishay.json");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
mediaContent = JSONReader.of(str)
|
||||
mc = JSONReader.of(str)
|
||||
.read(MediaContent.class);
|
||||
|
||||
Kryo kryo = new Kryo();
|
||||
@ -64,32 +58,29 @@ public class EishayWriteBinaryArrayMapping {
|
||||
}
|
||||
}
|
||||
|
||||
public int furySize() {
|
||||
return fury.serialize(mediaContent).length;
|
||||
// @Benchmark
|
||||
public void fastjson1UTF8Bytes(Blackhole bh) {
|
||||
bh.consume(com.alibaba.fastjson.JSON.toJSONBytes(mc, SerializerFeature.BeanToArray));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void fury(Blackhole bh) {
|
||||
bh.consume(
|
||||
fury.serialize(mediaContent)
|
||||
);
|
||||
@Benchmark
|
||||
public void fastjson2UTF8Bytes(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONBytes(mc, JSONWriter.Feature.BeanToArray));
|
||||
}
|
||||
|
||||
public int jsonbSize() {
|
||||
return JSONB.toBytes(mediaContent, JSONWriter.Feature.BeanToArray).length;
|
||||
return JSONB.toBytes(mc, JSONWriter.Feature.BeanToArray).length;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSONB.toBytes(mediaContent, JSONWriter.Feature.BeanToArray)
|
||||
);
|
||||
bh.consume(JSONB.toBytes(mc, JSONWriter.Feature.BeanToArray));
|
||||
}
|
||||
|
||||
public int kryoSize() {
|
||||
Output output = outputs.get();
|
||||
output.reset();
|
||||
kryos.get().writeObject(output, mediaContent);
|
||||
kryos.get().writeObject(output, mc);
|
||||
return output.toBytes().length;
|
||||
}
|
||||
|
||||
@ -97,17 +88,17 @@ public class EishayWriteBinaryArrayMapping {
|
||||
public void kryo(Blackhole bh) throws Exception {
|
||||
Output output = outputs.get();
|
||||
output.reset();
|
||||
kryos.get().writeObject(output, mediaContent);
|
||||
kryos.get().writeObject(output, mc);
|
||||
bh.consume(output.toBytes());
|
||||
}
|
||||
|
||||
public int protobufSize() {
|
||||
return MediaContentTransform.forward(mediaContent).toByteArray().length;
|
||||
return MediaContentTransform.forward(mc).toByteArray().length;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void protobuf(Blackhole bh) throws Exception {
|
||||
byte[] bytes = MediaContentTransform.forward(mediaContent).toByteArray();
|
||||
byte[] bytes = MediaContentTransform.forward(mc).toByteArray();
|
||||
bh.consume(bytes);
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,7 @@ package com.alibaba.fastjson2.benchmark.eishay;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.vo.MediaContent;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@ -24,16 +22,8 @@ public class EishayWriteUTF8Bytes {
|
||||
static MediaContent mc;
|
||||
static final ObjectMapper mapper = new ObjectMapper();
|
||||
static final Gson gson = new Gson();
|
||||
static final ObjectWriterProvider featuresProvider;
|
||||
static final JSONWriter.Context featuresContext;
|
||||
|
||||
static {
|
||||
ObjectWriterProvider provider = new ObjectWriterProvider();
|
||||
provider.setDisableReferenceDetect(true);
|
||||
provider.setDisableJSONB(true);
|
||||
provider.setDisableArrayMapping(true);
|
||||
provider.setDisableAutoType(true);
|
||||
featuresProvider = provider;
|
||||
featuresContext = new JSONWriter.Context(provider);
|
||||
try {
|
||||
InputStream is = EishayWriteUTF8Bytes.class.getClassLoader().getResourceAsStream("data/eishay.json");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
@ -54,10 +44,6 @@ public class EishayWriteUTF8Bytes {
|
||||
bh.consume(JSON.toJSONBytes(mc));
|
||||
}
|
||||
|
||||
public void fastjson2_features(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONBytes(mc, StandardCharsets.UTF_8, featuresContext));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jackson(Blackhole bh) throws Exception {
|
||||
bh.consume(mapper.writeValueAsBytes(mc));
|
||||
@ -74,7 +60,6 @@ public class EishayWriteUTF8Bytes {
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(EishayWriteUTF8Bytes.class.getName())
|
||||
.exclude(EishayWriteUTF8BytesTree.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
|
@ -289,8 +289,8 @@ public class EishayClassGen {
|
||||
}
|
||||
|
||||
public byte[][] genFuryBytes(int count) throws Exception {
|
||||
// org.apache.fury.ThreadSafeFury fury = org.apache.fury.Fury.builder()
|
||||
// .withLanguage(org.apache.fury.Language.JAVA)
|
||||
// io.fury.ThreadSafeFury fury = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .buildThreadSafeFury();
|
||||
|
@ -2,8 +2,7 @@ package com.alibaba.fastjson2.benchmark.eishay.vo;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
//@com.alibaba.fastjson2.annotation.JSONCompiled
|
||||
//@com.alibaba.fastjson2.annotation.JSONType(disableReferenceDetect = true, disableArrayMapping = true, disableSmartMatch = true, disableAutoType = true, disableJSONB = true)
|
||||
//@com.alibaba.fastjson2.annotation.JSONCompiled(referenceDetect = false)
|
||||
public class Image
|
||||
implements java.io.Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -3,8 +3,7 @@ package com.alibaba.fastjson2.benchmark.eishay.vo;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
//@com.alibaba.fastjson2.annotation.JSONCompiled
|
||||
//@com.alibaba.fastjson2.annotation.JSONType(disableReferenceDetect = true, disableArrayMapping = true, disableSmartMatch = true, disableAutoType = true, disableJSONB = true)
|
||||
//@com.alibaba.fastjson2.annotation.JSONCompiled(referenceDetect = false)
|
||||
@SuppressWarnings("serial")
|
||||
public class Media
|
||||
implements java.io.Serializable {
|
||||
|
@ -2,8 +2,7 @@ package com.alibaba.fastjson2.benchmark.eishay.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@com.alibaba.fastjson2.annotation.JSONCompiled
|
||||
//@com.alibaba.fastjson2.annotation.JSONType(disableReferenceDetect = true, disableArrayMapping = true, disableSmartMatch = true, disableAutoType = true, disableJSONB = true)
|
||||
//@com.alibaba.fastjson2.annotation.JSONCompiled(referenceDetect = false)
|
||||
@SuppressWarnings("serial")
|
||||
public class MediaContent
|
||||
implements java.io.Serializable {
|
||||
|
@ -1,32 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
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.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DateToString {
|
||||
static final Date date = new Date(1693836447048L);
|
||||
|
||||
@Benchmark
|
||||
public void dateToString(Blackhole bh) throws Throwable {
|
||||
bh.consume(date.toString());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(DateToString.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(1)
|
||||
.forks(1)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.LambdaMetafactory;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
public class DecimalDToString {
|
||||
static final BigInteger unscaledVal;
|
||||
static int scale = 2;
|
||||
static BigDecimal decimal;
|
||||
static BiFunction<BigDecimal, Boolean, String> LAYOUT_CHARS;
|
||||
|
||||
static {
|
||||
decimal = new BigDecimal("0.09313609545535894707057877894840203225612640380859375");
|
||||
unscaledVal = decimal.unscaledValue();
|
||||
|
||||
try {
|
||||
MethodHandles.Lookup lookup = JDKUtils.trustedLookup(BigDecimal.class);
|
||||
|
||||
MethodHandle handle = lookup.findVirtual(
|
||||
BigDecimal.class, "layoutChars", methodType(String.class, boolean.class)
|
||||
);
|
||||
|
||||
CallSite callSite = LambdaMetafactory.metafactory(
|
||||
lookup,
|
||||
"apply",
|
||||
methodType(BiFunction.class),
|
||||
methodType(Object.class, Object.class, Object.class),
|
||||
handle,
|
||||
methodType(String.class, BigDecimal.class, Boolean.class)
|
||||
);
|
||||
LAYOUT_CHARS = (BiFunction<BigDecimal, Boolean, String>) callSite.getTarget().invokeExact();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainString(Blackhole bh) {
|
||||
bh.consume(DecimalUtils.toString(unscaledVal, scale));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void layoutChars(Blackhole bh) {
|
||||
bh.consume(
|
||||
LAYOUT_CHARS.apply(decimal, Boolean.TRUE)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainStringDec(Blackhole bh) {
|
||||
bh.consume(
|
||||
decimal.toPlainString()
|
||||
);
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8UTF16(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('\u4e2d');
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.LambdaMetafactory;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
public class DecimalHugToString {
|
||||
static final BigInteger unscaledVal;
|
||||
static int scale = 2;
|
||||
static BigDecimal decimal;
|
||||
static BiFunction<BigDecimal, Boolean, String> LAYOUT_CHARS;
|
||||
|
||||
static {
|
||||
decimal = new BigDecimal("37335022433733502243.55");
|
||||
unscaledVal = decimal.unscaledValue();
|
||||
|
||||
try {
|
||||
MethodHandles.Lookup lookup = JDKUtils.trustedLookup(BigDecimal.class);
|
||||
|
||||
MethodHandle handle = lookup.findVirtual(
|
||||
BigDecimal.class, "layoutChars", methodType(String.class, boolean.class)
|
||||
);
|
||||
|
||||
CallSite callSite = LambdaMetafactory.metafactory(
|
||||
lookup,
|
||||
"apply",
|
||||
methodType(BiFunction.class),
|
||||
methodType(Object.class, Object.class, Object.class),
|
||||
handle,
|
||||
methodType(String.class, BigDecimal.class, Boolean.class)
|
||||
);
|
||||
LAYOUT_CHARS = (BiFunction<BigDecimal, Boolean, String>) callSite.getTarget().invokeExact();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainString(Blackhole bh) {
|
||||
bh.consume(DecimalUtils.toString(unscaledVal, scale));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void layoutChars(Blackhole bh) {
|
||||
bh.consume(LAYOUT_CHARS.apply(decimal, Boolean.TRUE));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainStringDec(Blackhole bh) {
|
||||
bh.consume(
|
||||
decimal.toPlainString()
|
||||
);
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8UTF16(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('\u4e2d');
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.LambdaMetafactory;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
public class DecimalLargeToString {
|
||||
static final BigInteger unscaledVal;
|
||||
static int scale = 2;
|
||||
static BigDecimal decimal;
|
||||
static BiFunction<BigDecimal, Boolean, String> LAYOUT_CHARS;
|
||||
|
||||
static {
|
||||
decimal = new BigDecimal("2715737727.55");
|
||||
unscaledVal = decimal.unscaledValue();
|
||||
|
||||
try {
|
||||
MethodHandles.Lookup lookup = JDKUtils.trustedLookup(BigDecimal.class);
|
||||
|
||||
MethodHandle handle = lookup.findVirtual(
|
||||
BigDecimal.class, "layoutChars", methodType(String.class, boolean.class)
|
||||
);
|
||||
|
||||
CallSite callSite = LambdaMetafactory.metafactory(
|
||||
lookup,
|
||||
"apply",
|
||||
methodType(BiFunction.class),
|
||||
methodType(Object.class, Object.class, Object.class),
|
||||
handle,
|
||||
methodType(String.class, BigDecimal.class, Boolean.class)
|
||||
);
|
||||
LAYOUT_CHARS = (BiFunction<BigDecimal, Boolean, String>) callSite.getTarget().invokeExact();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainString(Blackhole bh) {
|
||||
bh.consume(DecimalUtils.toString(unscaledVal, scale));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void layoutChars(Blackhole bh) {
|
||||
bh.consume(LAYOUT_CHARS.apply(decimal, Boolean.TRUE));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainStringDec(Blackhole bh) {
|
||||
bh.consume(
|
||||
decimal.toPlainString()
|
||||
);
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8UTF16(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('\u4e2d');
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.LambdaMetafactory;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
public class DecimalSmallToString {
|
||||
static final BigInteger unscaledVal;
|
||||
static int scale = 2;
|
||||
static BigDecimal decimal;
|
||||
static BiFunction<BigDecimal, Boolean, String> LAYOUT_CHARS;
|
||||
|
||||
static {
|
||||
decimal = new BigDecimal("415246.55");
|
||||
unscaledVal = decimal.unscaledValue();
|
||||
|
||||
try {
|
||||
MethodHandles.Lookup lookup = JDKUtils.trustedLookup(BigDecimal.class);
|
||||
|
||||
MethodHandle handle = lookup.findVirtual(
|
||||
BigDecimal.class, "layoutChars", methodType(String.class, boolean.class)
|
||||
);
|
||||
|
||||
CallSite callSite = LambdaMetafactory.metafactory(
|
||||
lookup,
|
||||
"apply",
|
||||
methodType(BiFunction.class),
|
||||
methodType(Object.class, Object.class, Object.class),
|
||||
handle,
|
||||
methodType(String.class, BigDecimal.class, Boolean.class)
|
||||
);
|
||||
LAYOUT_CHARS = (BiFunction<BigDecimal, Boolean, String>) callSite.getTarget().invokeExact();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainString(Blackhole bh) {
|
||||
bh.consume(DecimalUtils.toString(unscaledVal, scale));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void layoutChars(Blackhole bh) {
|
||||
bh.consume(
|
||||
LAYOUT_CHARS.apply(decimal, Boolean.TRUE)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainStringDec(Blackhole bh) {
|
||||
bh.consume(
|
||||
decimal.toPlainString()
|
||||
);
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8UTF16(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('\u4e2d');
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.LambdaMetafactory;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
public class DecimalToString {
|
||||
static final long unscaledVal = 123456;
|
||||
static int scale = 2;
|
||||
static BigDecimal decimal = BigDecimal.valueOf(unscaledVal, scale);
|
||||
static BiFunction<BigDecimal, Boolean, String> LAYOUT_CHARS;
|
||||
|
||||
static {
|
||||
try {
|
||||
MethodHandles.Lookup lookup = JDKUtils.trustedLookup(BigDecimal.class);
|
||||
|
||||
MethodHandle handle = lookup.findVirtual(
|
||||
BigDecimal.class, "layoutChars", methodType(String.class, boolean.class)
|
||||
);
|
||||
|
||||
CallSite callSite = LambdaMetafactory.metafactory(
|
||||
lookup,
|
||||
"apply",
|
||||
methodType(BiFunction.class),
|
||||
methodType(Object.class, Object.class, Object.class),
|
||||
handle,
|
||||
methodType(String.class, BigDecimal.class, Boolean.class)
|
||||
);
|
||||
LAYOUT_CHARS = (BiFunction<BigDecimal, Boolean, String>) callSite.getTarget().invokeExact();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainString(Blackhole bh) {
|
||||
bh.consume(DecimalUtils.toString(unscaledVal, scale));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void layoutChars(Blackhole bh) {
|
||||
bh.consume(LAYOUT_CHARS.apply(decimal, Boolean.TRUE));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toPlainStringDec(Blackhole bh) {
|
||||
bh.consume(decimal.toPlainString());
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
|
||||
public void toStringCharWithInt8UTF16(Blackhole bh) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('\u4e2d');
|
||||
result.append(2048);
|
||||
result.append(31337);
|
||||
result.append(0xbeefcace);
|
||||
result.append(9000);
|
||||
result.append(4711);
|
||||
result.append(1337);
|
||||
result.append(2100);
|
||||
result.append(2600);
|
||||
bh.consume(result.toString());
|
||||
}
|
||||
}
|
@ -1,508 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DecimalUtils {
|
||||
public static String toString(long unscaledVal, int scale) {
|
||||
if (scale == 0) {
|
||||
return Long.toString(unscaledVal);
|
||||
}
|
||||
|
||||
boolean negative = false;
|
||||
if (unscaledVal < 0) {
|
||||
unscaledVal = -unscaledVal;
|
||||
negative = true;
|
||||
}
|
||||
|
||||
int size = stringSize(unscaledVal);
|
||||
|
||||
byte[] buf;
|
||||
int off = 0;
|
||||
if (scale < 0) {
|
||||
buf = new byte[size - scale + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
getChars(unscaledVal, off + size, buf);
|
||||
Arrays.fill(buf, off + size, buf.length, (byte) '0');
|
||||
} else {
|
||||
int insertionPoint = size - scale;
|
||||
if (insertionPoint <= 0) {
|
||||
buf = new byte[size + 2 - insertionPoint + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
buf[off] = '0';
|
||||
buf[off + 1] = '.';
|
||||
|
||||
for (int i = 0; i < -insertionPoint; i++) {
|
||||
buf[off + i + 2] = '0';
|
||||
}
|
||||
getChars(unscaledVal, buf.length, buf);
|
||||
} else {
|
||||
long power = POWER_TEN[scale - 1];
|
||||
long div = unscaledVal / power;
|
||||
long rem = unscaledVal - div * power;
|
||||
int divSize = size - scale;
|
||||
buf = new byte[size + (negative ? 2 : 1)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
getChars(div, off + divSize, buf);
|
||||
buf[divSize + off] = '.';
|
||||
getChars(rem, buf.length, buf);
|
||||
}
|
||||
}
|
||||
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecated")
|
||||
public static String toString(BigInteger unscaledVal, int scale) {
|
||||
if (scale == 0) {
|
||||
return unscaledVal.toString(10);
|
||||
}
|
||||
|
||||
boolean negative = false;
|
||||
if (unscaledVal.signum() < 0) {
|
||||
negative = true;
|
||||
unscaledVal = unscaledVal.negate();
|
||||
}
|
||||
|
||||
String unscaledValString = unscaledVal.toString(10);
|
||||
|
||||
int size = unscaledValString.length();
|
||||
|
||||
byte[] buf;
|
||||
int off = 0;
|
||||
if (scale < 0) {
|
||||
buf = new byte[size - scale + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
unscaledValString.getBytes(0, size, buf, off);
|
||||
Arrays.fill(buf, off + size, buf.length, (byte) '0');
|
||||
} else {
|
||||
int insertionPoint = size - scale;
|
||||
if (insertionPoint <= 0) {
|
||||
buf = new byte[size + 2 - insertionPoint + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
buf[off] = '0';
|
||||
buf[off + 1] = '.';
|
||||
off += 2;
|
||||
|
||||
for (int i = 0; i < -insertionPoint; i++) {
|
||||
buf[off++] = '0';
|
||||
}
|
||||
|
||||
unscaledValString.getBytes(0, size, buf, off);
|
||||
} else {
|
||||
buf = new byte[size + (negative ? 2 : 1)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
|
||||
unscaledValString.getBytes(0, insertionPoint, buf, off);
|
||||
off += insertionPoint;
|
||||
buf[off] = '.';
|
||||
unscaledValString.getBytes(insertionPoint, size, buf, off + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
static final long[] POWER_TEN = {
|
||||
10,
|
||||
100,
|
||||
1000,
|
||||
10000,
|
||||
100000,
|
||||
1000000,
|
||||
10000000,
|
||||
100000000,
|
||||
1000000000,
|
||||
10000000000L,
|
||||
100000000000L,
|
||||
1000000000000L,
|
||||
10000000000000L,
|
||||
100000000000000L,
|
||||
1000000000000000L,
|
||||
10000000000000000L,
|
||||
100000000000000000L,
|
||||
1000000000000000000L,
|
||||
};
|
||||
|
||||
static String layout(long intCompact, int scale, boolean sci) {
|
||||
if (scale == 0) {
|
||||
return Long.toString(intCompact);
|
||||
}
|
||||
|
||||
long unscaledVal;
|
||||
boolean negative = false;
|
||||
if (intCompact < 0) {
|
||||
unscaledVal = -intCompact;
|
||||
negative = true;
|
||||
} else {
|
||||
unscaledVal = intCompact;
|
||||
}
|
||||
|
||||
int coeffLen = stringSize(unscaledVal);
|
||||
long adjusted = -(long) scale + (coeffLen - 1);
|
||||
|
||||
byte[] buf;
|
||||
int off = 0;
|
||||
if ((scale >= 0) && (adjusted >= -6)) {
|
||||
int pad = scale - coeffLen;
|
||||
if (pad >= 0) {
|
||||
buf = new byte[coeffLen + 2 + pad + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
buf[off] = '0';
|
||||
buf[off + 1] = '.';
|
||||
off += 2;
|
||||
for (int i = 0; i < pad; i++) {
|
||||
buf[off++] = '0';
|
||||
}
|
||||
getChars(unscaledVal, buf.length, buf);
|
||||
} else {
|
||||
buf = new byte[coeffLen + 1 + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
|
||||
long power = POWER_TEN[scale - 1];
|
||||
long div = unscaledVal / power;
|
||||
long rem = unscaledVal - div * power;
|
||||
getChars(div, off + coeffLen - scale, buf);
|
||||
buf[off + coeffLen - scale] = '.';
|
||||
getChars(rem, off + coeffLen + 1, buf);
|
||||
}
|
||||
} else {
|
||||
if (sci) {
|
||||
if (coeffLen > 1) {
|
||||
int adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[coeffLen + adjustedSize + 1 + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
long power = POWER_TEN[coeffLen - 2];
|
||||
long div = unscaledVal / power;
|
||||
long rem = unscaledVal - div * power;
|
||||
buf[off] = (byte) (div + '0');
|
||||
buf[off + 1] = '.';
|
||||
getChars(rem, off + coeffLen + 1, buf);
|
||||
off += coeffLen + 1;
|
||||
} else {
|
||||
int adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[adjustedSize + (negative ? 2 : 1)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
buf[off++] = (byte) (unscaledVal + '0');
|
||||
}
|
||||
} else {
|
||||
int sig = (int) (adjusted % 3);
|
||||
if (sig < 0) {
|
||||
sig += 3; // [adjusted was negative]
|
||||
}
|
||||
adjusted -= sig; // now a multiple of 3
|
||||
sig++;
|
||||
|
||||
int adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
if (unscaledVal == 0) {
|
||||
switch (sig) {
|
||||
case 1: {
|
||||
buf = new byte[adjustedSize + 1];
|
||||
buf[0] = '0'; // exponent is a multiple of three
|
||||
off = 1;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
adjusted += 3;
|
||||
adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[adjustedSize + 4];
|
||||
buf[0] = '0';
|
||||
buf[1] = '.';
|
||||
buf[2] = '0';
|
||||
buf[3] = '0';
|
||||
off = 4;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
adjusted += 3;
|
||||
adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[adjustedSize + 3];
|
||||
buf[0] = '0';
|
||||
buf[1] = '.';
|
||||
buf[2] = '0';
|
||||
off = 3;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new AssertionError("Unexpected sig value " + sig);
|
||||
}
|
||||
} else if (sig >= coeffLen) {
|
||||
buf = new byte[adjustedSize + (negative ? 2 : 1) + sig - coeffLen];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
getChars(unscaledVal, off + coeffLen, buf);
|
||||
off += coeffLen;
|
||||
for (int i = sig - coeffLen; i > 0; i--) {
|
||||
buf[off++] = '0';
|
||||
}
|
||||
} else {
|
||||
buf = new byte[adjustedSize + (negative ? 2 : 1) + coeffLen];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
|
||||
long power = POWER_TEN[coeffLen - sig - 1];
|
||||
long div = unscaledVal / power;
|
||||
long rem = unscaledVal - div * power;
|
||||
getChars(div, off + sig, buf);
|
||||
buf[off + sig] = '.';
|
||||
getChars(rem, off + coeffLen + 1, buf);
|
||||
off += coeffLen + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (adjusted != 0) { // [!sci could have made 0]
|
||||
buf[off] = 'E';
|
||||
buf[off + 1] = (byte) (adjusted > 0 ? '+' : '-');
|
||||
getChars(Math.abs(adjusted), buf.length, buf);
|
||||
}
|
||||
}
|
||||
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
static String layout(BigInteger intVal, int scale, boolean sci) {
|
||||
if (scale == 0) {
|
||||
return intVal.toString();
|
||||
}
|
||||
|
||||
BigInteger unscaledVal;
|
||||
boolean negative = false;
|
||||
int signum = intVal.signum();
|
||||
if (signum < 0) {
|
||||
unscaledVal = intVal.negate();
|
||||
negative = true;
|
||||
} else {
|
||||
unscaledVal = intVal;
|
||||
}
|
||||
|
||||
byte[] buf;
|
||||
int off = 0;
|
||||
String unscaledValString = unscaledVal.toString(10);
|
||||
byte[] coeff = unscaledValString.getBytes(StandardCharsets.ISO_8859_1);
|
||||
int coeffLen = coeff.length;
|
||||
long adjusted = -(long) scale + (coeffLen - 1);
|
||||
if ((scale >= 0) && (adjusted >= -6)) {
|
||||
int pad = scale - coeffLen;
|
||||
if (pad >= 0) {
|
||||
buf = new byte[coeffLen + 2 + pad + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
buf[off] = '0';
|
||||
buf[off + 1] = '.';
|
||||
off += 2;
|
||||
for (int i = 0; i < pad; i++) {
|
||||
buf[off++] = '0';
|
||||
}
|
||||
System.arraycopy(coeff, 0, buf, off, coeffLen);
|
||||
} else {
|
||||
buf = new byte[coeffLen + 1 + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
|
||||
System.arraycopy(coeff, 0, buf, off, -pad);
|
||||
buf[off - pad] = '.';
|
||||
System.arraycopy(coeff, -pad, buf, off - pad + 1, scale);
|
||||
}
|
||||
} else {
|
||||
if (sci) { // Scientific notation
|
||||
if (coeffLen > 1) {
|
||||
int adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[coeffLen + adjustedSize + 1 + (negative ? 1 : 0)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
buf[off] = coeff[0];
|
||||
buf[off + 1] = '.';
|
||||
System.arraycopy(coeff, 1, buf, off + 2, coeffLen - 1);
|
||||
off += coeffLen + 1;
|
||||
} else {
|
||||
int adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[adjustedSize + (negative ? 2 : 1)];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
buf[off++] = coeff[0];
|
||||
}
|
||||
} else {
|
||||
int sig = (int) (adjusted % 3);
|
||||
if (sig < 0) {
|
||||
sig += 3; // [adjusted was negative]
|
||||
}
|
||||
adjusted -= sig; // now a multiple of 3
|
||||
sig++;
|
||||
|
||||
int adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
if (signum == 0) {
|
||||
switch (sig) {
|
||||
case 1: {
|
||||
buf = new byte[adjustedSize + 1];
|
||||
buf[0] = '0'; // exponent is a multiple of three
|
||||
off = 1;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
adjusted += 3;
|
||||
adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[adjustedSize + 4];
|
||||
buf[0] = '0';
|
||||
buf[1] = '.';
|
||||
buf[2] = '0';
|
||||
buf[3] = '0';
|
||||
off = 4;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
adjusted += 3;
|
||||
adjustedSize = adjusted != 0 ? stringSize(Math.abs(adjusted)) + 2 : 0;
|
||||
buf = new byte[adjustedSize + 3];
|
||||
buf[0] = '0';
|
||||
buf[1] = '.';
|
||||
buf[2] = '0';
|
||||
off = 3;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new AssertionError("Unexpected sig value " + sig);
|
||||
}
|
||||
} else if (sig >= coeffLen) {
|
||||
buf = new byte[adjustedSize + (negative ? 2 : 1) + sig - coeffLen];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
System.arraycopy(coeff, 0, buf, off, coeffLen);
|
||||
off += coeffLen;
|
||||
for (int i = sig - coeffLen; i > 0; i--) {
|
||||
buf[off++] = '0';
|
||||
}
|
||||
} else {
|
||||
buf = new byte[adjustedSize + (negative ? 2 : 1) + coeffLen];
|
||||
if (negative) {
|
||||
buf[0] = '-';
|
||||
off = 1;
|
||||
}
|
||||
|
||||
System.arraycopy(coeff, 0, buf, off, sig);
|
||||
buf[off + sig] = '.';
|
||||
System.arraycopy(coeff, sig, buf, off + sig + 1, coeffLen - sig);
|
||||
off += coeffLen + 1;
|
||||
}
|
||||
}
|
||||
if (adjusted != 0) { // [!sci could have made 0]
|
||||
buf[off] = 'E';
|
||||
buf[off + 1] = (byte) (adjusted > 0 ? '+' : '-');
|
||||
getChars(Math.abs(adjusted), buf.length, buf);
|
||||
}
|
||||
}
|
||||
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
static int stringSize(long x) {
|
||||
long p = 10;
|
||||
for (int i = 1; i < 19; i++) {
|
||||
if (x < p) {
|
||||
return i;
|
||||
}
|
||||
p = 10 * p;
|
||||
}
|
||||
return 19;
|
||||
}
|
||||
|
||||
public static final short[] PACKED_DIGITS = new short[]{
|
||||
0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830, 0x3930,
|
||||
0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731, 0x3831, 0x3931,
|
||||
0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732, 0x3832, 0x3932,
|
||||
0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733, 0x3833, 0x3933,
|
||||
0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734, 0x3834, 0x3934,
|
||||
0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935,
|
||||
0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836, 0x3936,
|
||||
0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737, 0x3837, 0x3937,
|
||||
0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738, 0x3838, 0x3938,
|
||||
0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739, 0x3839, 0x3939
|
||||
};
|
||||
|
||||
static void getChars(long i, int index, byte[] buf) {
|
||||
long q;
|
||||
int charPos = index;
|
||||
|
||||
boolean negative = (i < 0);
|
||||
if (negative) {
|
||||
i = -i;
|
||||
}
|
||||
|
||||
// Get 2 digits/iteration using longs until quotient fits into an int
|
||||
while (i > Integer.MAX_VALUE) {
|
||||
q = i / 100;
|
||||
short v = PACKED_DIGITS[(int) (i - q * 100)];
|
||||
buf[--charPos] = (byte) (v >> 8);
|
||||
buf[--charPos] = (byte) v;
|
||||
i = q;
|
||||
}
|
||||
|
||||
// Get 2 digits/iteration using ints
|
||||
int q2;
|
||||
int i2 = (int) i;
|
||||
while (i2 >= 100) {
|
||||
q2 = i2 / 100;
|
||||
short v = PACKED_DIGITS[i2 - q2 * 100];
|
||||
buf[--charPos] = (byte) (v >> 8);
|
||||
buf[--charPos] = (byte) v;
|
||||
i2 = q2;
|
||||
}
|
||||
|
||||
// We know there are at most two digits left at this point.
|
||||
if (i2 > 9) {
|
||||
short v = PACKED_DIGITS[i2];
|
||||
buf[--charPos] = (byte) (v >> 8);
|
||||
buf[--charPos] = (byte) v;
|
||||
} else {
|
||||
buf[--charPos] = (byte) ('0' + i2);
|
||||
}
|
||||
|
||||
if (negative) {
|
||||
buf[charPos - 1] = (byte) '-';
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.NumberUtils;
|
||||
import com.alibaba.fastjson2.util.DoubleToDecimal;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
@ -23,7 +23,7 @@ public class DoubleToString {
|
||||
@Benchmark
|
||||
public void ryu(Blackhole bh) throws Throwable {
|
||||
byte[] bytes = new byte[24];
|
||||
int size = NumberUtils.writeDouble(bytes, 0, d, true);
|
||||
int size = DoubleToDecimal.toString(d, bytes, 0, true);
|
||||
String str = new String(bytes, 0, 0, size);
|
||||
bh.consume(str);
|
||||
}
|
||||
@ -36,7 +36,7 @@ public class DoubleToString {
|
||||
// @Benchmark
|
||||
public void ryuFloat(Blackhole bh) throws Throwable {
|
||||
byte[] bytes = new byte[15];
|
||||
int size = NumberUtils.writeFloat(bytes, 0, f, false);
|
||||
int size = DoubleToDecimal.toString(f, bytes, 0, false);
|
||||
String str = new String(bytes, 0, 0, size);
|
||||
bh.consume(str);
|
||||
}
|
||||
|
@ -1,123 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
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.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.alibaba.fastjson2.util.IOUtils.PACKED_DIGITS;
|
||||
import static com.alibaba.fastjson2.util.JDKUtils.*;
|
||||
|
||||
public class LocalDateTimeFormat19 {
|
||||
static final String pattern = "yyyy-MM-dd HH:mm:ss";
|
||||
static DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
static LocalDateTime ldt = LocalDateTime.of(2023, 8, 16, 20, 21, 15);
|
||||
|
||||
@Benchmark
|
||||
public void javaTimeFormatter(Blackhole bh) throws Throwable {
|
||||
String str = formatter.format(ldt);
|
||||
bh.consume(str);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void formatYMDHMS19(Blackhole bh) throws Throwable {
|
||||
bh.consume(formatYMDHMS19(ldt));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void formatYMDHMS19_o(Blackhole bh) throws Throwable {
|
||||
bh.consume(formatYMDHMS19_o(ldt));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(LocalDateTimeFormat19.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(1)
|
||||
.forks(1)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
|
||||
public static String formatYMDHMS19(LocalDateTime ldt) {
|
||||
int year = ldt.getYear();
|
||||
int month = ldt.getMonthValue();
|
||||
int dayOfMonth = ldt.getDayOfMonth();
|
||||
int hour = ldt.getHour();
|
||||
int minute = ldt.getMinute();
|
||||
int second = ldt.getSecond();
|
||||
|
||||
byte[] bytes = new byte[19];
|
||||
int y01 = year / 100;
|
||||
int y23 = year - y01 * 100;
|
||||
UNSAFE.putShort(bytes, ARRAY_BYTE_BASE_OFFSET, PACKED_DIGITS[y01]);
|
||||
UNSAFE.putShort(bytes, ARRAY_BYTE_BASE_OFFSET + 2, PACKED_DIGITS[y23]);
|
||||
bytes[4] = '-';
|
||||
UNSAFE.putShort(bytes, ARRAY_BYTE_BASE_OFFSET + 5, PACKED_DIGITS[month]);
|
||||
bytes[7] = '-';
|
||||
UNSAFE.putShort(bytes, ARRAY_BYTE_BASE_OFFSET + 8, PACKED_DIGITS[dayOfMonth]);
|
||||
bytes[10] = ' ';
|
||||
UNSAFE.putShort(bytes, ARRAY_BYTE_BASE_OFFSET + 11, PACKED_DIGITS[hour]);
|
||||
bytes[13] = ':';
|
||||
UNSAFE.putShort(bytes, ARRAY_BYTE_BASE_OFFSET + 14, PACKED_DIGITS[minute]);
|
||||
bytes[16] = ':';
|
||||
UNSAFE.putShort(bytes, ARRAY_BYTE_BASE_OFFSET + 17, PACKED_DIGITS[second]);
|
||||
return STRING_CREATOR_JDK11.apply(bytes, LATIN1);
|
||||
}
|
||||
|
||||
static String formatYMDHMS19_o(LocalDateTime ldt) {
|
||||
int year = ldt.getYear();
|
||||
int month = ldt.getMonthValue();
|
||||
int dayOfMonth = ldt.getDayOfMonth();
|
||||
int hour = ldt.getHour();
|
||||
int minute = ldt.getMinute();
|
||||
int second = ldt.getSecond();
|
||||
|
||||
int y0 = year / 1000 + '0';
|
||||
int y1 = (year / 100) % 10 + '0';
|
||||
int y2 = (year / 10) % 10 + '0';
|
||||
int y3 = year % 10 + '0';
|
||||
int m0 = month / 10 + '0';
|
||||
int m1 = month % 10 + '0';
|
||||
int d0 = dayOfMonth / 10 + '0';
|
||||
int d1 = dayOfMonth % 10 + '0';
|
||||
int h0 = hour / 10 + '0';
|
||||
int h1 = hour % 10 + '0';
|
||||
int i0 = minute / 10 + '0';
|
||||
int i1 = minute % 10 + '0';
|
||||
int s0 = second / 10 + '0';
|
||||
int s1 = second % 10 + '0';
|
||||
|
||||
byte[] bytes = new byte[19];
|
||||
bytes[0] = (byte) y0;
|
||||
bytes[1] = (byte) y1;
|
||||
bytes[2] = (byte) y2;
|
||||
bytes[3] = (byte) y3;
|
||||
bytes[4] = '-';
|
||||
bytes[5] = (byte) m0;
|
||||
bytes[6] = (byte) m1;
|
||||
bytes[7] = '-';
|
||||
bytes[8] = (byte) d0;
|
||||
bytes[9] = (byte) d1;
|
||||
bytes[10] = ' ';
|
||||
bytes[11] = (byte) h0;
|
||||
bytes[12] = (byte) h1;
|
||||
bytes[13] = ':';
|
||||
bytes[14] = (byte) i0;
|
||||
bytes[15] = (byte) i1;
|
||||
bytes[16] = ':';
|
||||
bytes[17] = (byte) s0;
|
||||
bytes[18] = (byte) s1;
|
||||
|
||||
return JDKUtils.STRING_CREATOR_JDK11.apply(bytes, JDKUtils.LATIN1);
|
||||
}
|
||||
}
|
@ -111,7 +111,7 @@ public class SimpleDateFormatX
|
||||
int dom = 31;
|
||||
switch (month) {
|
||||
case 2:
|
||||
boolean isLeapYear = (year & 15) == 0 ? (year & 3) == 0 : (year & 3) == 0 && year % 100 != 0;
|
||||
boolean isLeapYear = ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0);
|
||||
dom = isLeapYear ? 29 : 28;
|
||||
break;
|
||||
case 4:
|
||||
|
@ -249,7 +249,7 @@ public class UUIDUtils {
|
||||
|
||||
static void putChar(byte[] val, int index, int c) {
|
||||
index <<= 1;
|
||||
val[index] = (byte) (c >> HI_BYTE_SHIFT);
|
||||
val[index + 1] = (byte) (c >> LO_BYTE_SHIFT);
|
||||
val[index++] = (byte) (c >> HI_BYTE_SHIFT);
|
||||
val[index] = (byte) (c >> LO_BYTE_SHIFT);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.geoip;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GeoIP {
|
||||
private String as;
|
||||
private String city;
|
||||
private String country;
|
||||
private String countryCode;
|
||||
private String isp;
|
||||
private double lat;
|
||||
private double lon;
|
||||
private String org;
|
||||
private String query;
|
||||
private String region;
|
||||
private String regionName;
|
||||
private String status;
|
||||
private String timezone;
|
||||
private String zip;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.geoip;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.EishayParseStringNoneCache;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.EishayParseStringPretty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
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.io.InputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GeoIPParseString {
|
||||
static String str;
|
||||
static final ObjectMapper mapper = new ObjectMapper();
|
||||
static final Gson gson = new Gson();
|
||||
|
||||
static {
|
||||
try {
|
||||
InputStream is = GeoIPParseString.class.getClassLoader().getResourceAsStream("data/geoip.json");
|
||||
str = IOUtils.toString(is, "UTF-8");
|
||||
JSON.parseObject(str, GeoIP.class);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson1(Blackhole bh) {
|
||||
bh.consume(com.alibaba.fastjson.JSON.parseObject(str, GeoIP.class));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(str, GeoIP.class));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jackson(Blackhole bh) throws Exception {
|
||||
bh.consume(mapper.readValue(str, GeoIP.class));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void wastjson(Blackhole bh) throws Exception {
|
||||
bh.consume(
|
||||
io.github.wycst.wast.json.JSON.parseObject(str, GeoIP.class)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void gson(Blackhole bh) throws Exception {
|
||||
bh.consume(
|
||||
gson.fromJson(str, GeoIP.class)
|
||||
);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(GeoIPParseString.class.getName())
|
||||
.exclude(EishayParseStringPretty.class.getName())
|
||||
.exclude(EishayParseStringNoneCache.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
.forks(1)
|
||||
.threads(16)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.geoip;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
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.io.InputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GeoIPWriteString {
|
||||
static GeoIP object;
|
||||
static final ObjectMapper mapper = new ObjectMapper();
|
||||
static final Gson gson = new Gson();
|
||||
|
||||
static {
|
||||
try {
|
||||
InputStream is = GeoIPWriteString.class.getClassLoader().getResourceAsStream("data/geoip.json");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
object = JSONReader.of(str).read(GeoIP.class);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson1(Blackhole bh) {
|
||||
bh.consume(com.alibaba.fastjson.JSON.toJSONString(object));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONString(object));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jackson(Blackhole bh) throws Exception {
|
||||
bh.consume(mapper.writeValueAsString(object));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void wastjson(Blackhole bh) throws Exception {
|
||||
bh.consume(
|
||||
io.github.wycst.wast.json.JSON.toJsonString(object)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void gson(Blackhole bh) throws Exception {
|
||||
bh.consume(
|
||||
gson.toJson(object)
|
||||
);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(GeoIPWriteString.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.warmupIterations(3)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
.forks(1)
|
||||
.threads(16)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.issues;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Issue2407 {
|
||||
static String str;
|
||||
static byte[] utf8;
|
||||
|
||||
static {
|
||||
try {
|
||||
InputStream is = Issue2407.class.getClassLoader().getResourceAsStream("issue/issue2407.json");
|
||||
str = IOUtils.toString(is, "UTF-8");
|
||||
utf8 = str.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void parseArray(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.parseArray(str)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void parseArray1(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.parseArray(str, Bean.class)
|
||||
);
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void parseArray1_utf8(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.parseArray(utf8, Bean.class)
|
||||
);
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
public String content;
|
||||
public String hostName;
|
||||
public String uniqueKey;
|
||||
public String originalAppName;
|
||||
public String odinLeaf;
|
||||
public long logTime;
|
||||
public long logId;
|
||||
public String appName;
|
||||
public String queryFrom;
|
||||
public String logName;
|
||||
public int isService;
|
||||
public long pathId;
|
||||
public String timestamp;
|
||||
public long collectTime;
|
||||
public String fileKey;
|
||||
public String parentPath;
|
||||
public long offset;
|
||||
public long preOffset;
|
||||
@JSONField(name = "ENV_ODIN_SU")
|
||||
public String envOdinSu;
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CompiledJson
|
||||
//@com.alibaba.fastjson2.annotation.JSONCompiled
|
||||
public class Clients {
|
||||
private List<Client> clients;
|
||||
|
||||
@ -24,7 +23,6 @@ public class Clients {
|
||||
}
|
||||
|
||||
@CompiledJson
|
||||
// @com.alibaba.fastjson2.annotation.JSONCompiled
|
||||
public static final class Client {
|
||||
private long id;
|
||||
private int index;
|
||||
|
@ -58,11 +58,6 @@ public class ClientsParseUTF8Bytes {
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void wast(Blackhole bh) {
|
||||
bh.consume(io.github.wycst.wast.json.JSON.parseObject(utf8Bytes, Clients.class));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(ClientsParseUTF8Bytes.class.getName())
|
||||
|
@ -1,99 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.jjb;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.dslplatform.json.DslJson;
|
||||
import com.dslplatform.json.runtime.Settings;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
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.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ClientsWriteCNBytes {
|
||||
static Clients clients;
|
||||
static final ObjectMapper mapper = new ObjectMapper();
|
||||
static final Gson gson = new Gson();
|
||||
static final DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().includeServiceLoader());
|
||||
static final ThreadLocal<ByteArrayOutputStream> bytesOutLocal = ThreadLocal.withInitial(() -> new ByteArrayOutputStream());
|
||||
|
||||
static {
|
||||
try {
|
||||
InputStream is = ClientsWriteCNBytes.class.getClassLoader().getResourceAsStream("data/jjb/client_cn.json");
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
clients = JSONReader.of(str)
|
||||
.read(Clients.class);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONBytes(clients));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void wast(Blackhole bh) {
|
||||
bh.consume(io.github.wycst.wast.json.JSON.toJsonBytes(clients));
|
||||
}
|
||||
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(JSONB.toBytes(clients));
|
||||
}
|
||||
|
||||
public void jsonb_beanToArray(Blackhole bh) {
|
||||
bh.consume(JSONB.toBytes(clients, JSONWriter.Feature.BeanToArray, JSONWriter.Feature.FieldBased));
|
||||
}
|
||||
|
||||
public void fastjson2_str(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONString(clients));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void dsljson(Blackhole bh) throws IOException {
|
||||
ByteArrayOutputStream bytesOut = bytesOutLocal.get();
|
||||
bytesOut.reset();
|
||||
dslJson.serialize(clients, bytesOut);
|
||||
byte[] bytes = bytesOut.toByteArray();
|
||||
bh.consume(bytes);
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void jackson(Blackhole bh) throws Exception {
|
||||
bh.consume(mapper.writeValueAsBytes(clients));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void gson(Blackhole bh) throws Exception {
|
||||
bh.consume(gson
|
||||
.toJson(clients)
|
||||
.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(ClientsWriteCNBytes.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
.forks(2)
|
||||
.threads(16)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
@ -46,11 +46,6 @@ public class ClientsWriteUTF8Bytes {
|
||||
bh.consume(JSON.toJSONBytes(clients));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void wast(Blackhole bh) {
|
||||
bh.consume(io.github.wycst.wast.json.JSON.toJsonBytes(clients));
|
||||
}
|
||||
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(JSONB.toBytes(clients));
|
||||
}
|
||||
|
@ -22,17 +22,13 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class UsersParseUTF8Bytes {
|
||||
static byte[] utf8Bytes;
|
||||
static char[] chars;
|
||||
static String str;
|
||||
static final ObjectMapper mapper = new ObjectMapper();
|
||||
static final Gson gson = new Gson();
|
||||
static final DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().includeServiceLoader());
|
||||
static {
|
||||
try {
|
||||
InputStream is = UsersParseUTF8Bytes.class.getClassLoader().getResourceAsStream("data/jjb/user.json");
|
||||
str = IOUtils.toString(is, "UTF-8");
|
||||
utf8Bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
chars = str.toCharArray();
|
||||
utf8Bytes = IOUtils.toString(is, "UTF-8").getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -41,27 +37,11 @@ public class UsersParseUTF8Bytes {
|
||||
@Benchmark
|
||||
public void fastjson2(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(utf8Bytes, Users.class));
|
||||
// zulu17.40.19 : 3515 4708
|
||||
// zulu17.40.19 : 3515
|
||||
// zulu17.40.19_vec : 338
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void fastjson2_str(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(str, Users.class));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void fastjson2_chars(Blackhole bh) {
|
||||
bh.consume(JSON.parseObject(chars, Users.class));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void wast(Blackhole bh) {
|
||||
// zulu17.40.19 : 3221
|
||||
bh.consume(io.github.wycst.wast.json.JSON.parseObject(utf8Bytes, Users.class));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void dsljson(Blackhole bh) throws IOException {
|
||||
bh.consume(dslJson.deserialize(Users.class, utf8Bytes, utf8Bytes.length));
|
||||
// zulu17.40.19 : 3560
|
||||
|
@ -46,16 +46,6 @@ public class UsersWriteUTF8Bytes {
|
||||
bh.consume(JSON.toJSONBytes(users));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void wast(Blackhole bh) {
|
||||
bh.consume(io.github.wycst.wast.json.JSON.toJsonBytes(users));
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
public void fastjson2_str(Blackhole bh) {
|
||||
bh.consume(JSON.toJSONString(users));
|
||||
}
|
||||
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(JSONB.toBytes(users));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.benchmark.primitves.vo.BigDecimal20Field;
|
||||
import com.caucho.hessian.io.Hessian2Input;
|
||||
import com.caucho.hessian.io.Hessian2Output;
|
||||
@ -27,6 +28,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BigDecimal20 {
|
||||
static String str;
|
||||
static BigDecimal20Field bean;
|
||||
static byte[] jsonbBytes;
|
||||
static ObjectMapper mapper = new ObjectMapper();
|
||||
static Gson gson = new Gson();
|
||||
@ -35,11 +37,11 @@ public class BigDecimal20 {
|
||||
|
||||
static byte[] hessianBytes;
|
||||
|
||||
// static org.apache.fury.ThreadSafeFury furyCompatible = org.apache.fury.Fury.builder()
|
||||
// .withLanguage(org.apache.fury.Language.JAVA)
|
||||
// static io.fury.ThreadSafeFury furyCompatible = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .withCompatibleMode(org.apache.fury.serializers.CompatibleMode.COMPATIBLE)
|
||||
// .withCompatibleMode(io.fury.serializers.CompatibleMode.COMPATIBLE)
|
||||
// .buildThreadSafeFury();
|
||||
// static byte[] furyCompatibleBytes;
|
||||
|
||||
@ -47,7 +49,7 @@ public class BigDecimal20 {
|
||||
try {
|
||||
InputStream is = BigDecimal20.class.getClassLoader().getResourceAsStream("data/dec20.json");
|
||||
str = IOUtils.toString(is, "UTF-8");
|
||||
BigDecimal20Field bean = JSON.parseObject(str, BigDecimal20Field.class);
|
||||
bean = JSON.parseObject(str, BigDecimal20Field.class);
|
||||
jsonbBytes = JSONB.toBytes(bean);
|
||||
|
||||
kryo = new Kryo();
|
||||
@ -86,6 +88,12 @@ public class BigDecimal20 {
|
||||
);
|
||||
}
|
||||
|
||||
public void fastjson2_ser(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.toJSONBytes(bean, JSONWriter.Feature.BeanToArray)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(
|
||||
|
@ -1,49 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class BigDecimalArrayWrite {
|
||||
static final BigDecimal[] decimals;
|
||||
static {
|
||||
String str = "[\n" +
|
||||
"\t13815.355,\n" +
|
||||
"\t420910.191,\n" +
|
||||
"\t167949.164,\n" +
|
||||
"\t942468.967,\n" +
|
||||
"\t266528.244,\n" +
|
||||
"\t776802.173,\n" +
|
||||
"\t110997.327,\n" +
|
||||
"\t468119.875,\n" +
|
||||
"\t727720.110,\n" +
|
||||
"\t62399.251,\n" +
|
||||
"\t431677.640,\n" +
|
||||
"\t707775.897,\n" +
|
||||
"\t887747.151,\n" +
|
||||
"\t141447.251,\n" +
|
||||
"\t999492.584,\n" +
|
||||
"\t342105.052,\n" +
|
||||
"\t806888.395,\n" +
|
||||
"\t141485.712,\n" +
|
||||
"\t549815.092,\n" +
|
||||
"\t816489.903\n" +
|
||||
"]";
|
||||
decimals = JSON.parseObject(str, BigDecimal[].class);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.toJSONBytes(decimals)
|
||||
);
|
||||
}
|
||||
|
||||
public void fastjson2_str(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.toJSONString(decimals)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class BigDecimalArrayWrite4 {
|
||||
static final BigDecimal[] decimals;
|
||||
static {
|
||||
String str = "[\n" +
|
||||
"\t13815.1355,\n" +
|
||||
"\t420910.1191,\n" +
|
||||
"\t167949.1164,\n" +
|
||||
"\t942468.1967,\n" +
|
||||
"\t266528.1244,\n" +
|
||||
"\t776802.1173,\n" +
|
||||
"\t110997.1327,\n" +
|
||||
"\t468119.1875,\n" +
|
||||
"\t727720.1110,\n" +
|
||||
"\t62399.1251,\n" +
|
||||
"\t431677.1640,\n" +
|
||||
"\t707775.1897,\n" +
|
||||
"\t887747.1151,\n" +
|
||||
"\t141447.1251,\n" +
|
||||
"\t999492.1584,\n" +
|
||||
"\t342105.1052,\n" +
|
||||
"\t806888.1395,\n" +
|
||||
"\t141485.1712,\n" +
|
||||
"\t549815.1092,\n" +
|
||||
"\t816489.1903\n" +
|
||||
"]";
|
||||
decimals = JSON.parseObject(str, BigDecimal[].class);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.toJSONBytes(decimals)
|
||||
);
|
||||
}
|
||||
|
||||
public void fastjson2_str(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.toJSONString(decimals)
|
||||
);
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.benchmark.primitves.vo.BigInteger20Field;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
@ -50,12 +49,6 @@ public class BigInteger20 {
|
||||
);
|
||||
}
|
||||
|
||||
public void fastjson2_array_bytes(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.toJSONBytes(bean, JSONWriter.Feature.BeanToArray)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void jsonb(Blackhole bh) {
|
||||
bh.consume(
|
||||
|
@ -1,37 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
public class ByteBench {
|
||||
private static final byte[] VALUES;
|
||||
|
||||
static {
|
||||
byte[] bytes = new byte[Byte.MAX_VALUE - Byte.MIN_VALUE];
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
bytes[i] = (byte) (Byte.MIN_VALUE + i);
|
||||
}
|
||||
VALUES = bytes;
|
||||
}
|
||||
|
||||
public void utf8(Blackhole BH) {
|
||||
JSONWriter jsonWriter = JSONWriter.ofUTF8();
|
||||
jsonWriter.writeAny(VALUES);
|
||||
BH.consume(jsonWriter.getBytes());
|
||||
jsonWriter.close();
|
||||
}
|
||||
|
||||
public void utf16(Blackhole BH) {
|
||||
JSONWriter jsonWriter = JSONWriter.ofUTF16();
|
||||
jsonWriter.writeAny(VALUES);
|
||||
BH.consume(jsonWriter.toString());
|
||||
jsonWriter.close();
|
||||
}
|
||||
|
||||
public void jsonb(Blackhole BH) {
|
||||
JSONWriter jsonWriter = JSONWriter.ofJSONB();
|
||||
jsonWriter.writeAny(VALUES);
|
||||
BH.consume(jsonWriter.getBytes());
|
||||
jsonWriter.close();
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.benchmark.primitves.vo.Int20Field;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@ -20,6 +21,7 @@ public class IntValue20 {
|
||||
static final Class OBJECT_CLASS = Int20Field.class;
|
||||
static String str;
|
||||
static byte[] jsonbBytes;
|
||||
static Object object;
|
||||
static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public IntValue20() {
|
||||
@ -29,6 +31,7 @@ public class IntValue20 {
|
||||
jsonbBytes = JSONB.toBytes(
|
||||
JSON.parseObject(str, OBJECT_CLASS)
|
||||
);
|
||||
object = JSON.parseObject(str, OBJECT_CLASS);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -55,6 +58,12 @@ public class IntValue20 {
|
||||
);
|
||||
}
|
||||
|
||||
public void fastjson2_ser(Blackhole bh) {
|
||||
bh.consume(
|
||||
JSON.toJSONBytes(object, JSONWriter.Feature.BeanToArray)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastjson2_jsonb(Blackhole bh) {
|
||||
bh.consume(
|
||||
|
@ -1,42 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class LocalDateBench {
|
||||
private static final LocalDate VALUE = LocalDate.of(2024, 2, 20);
|
||||
|
||||
public void utf8(Blackhole BH) {
|
||||
JSONWriter jsonWriter = JSONWriter.ofUTF8();
|
||||
|
||||
jsonWriter.startArray();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
if (i != 0) {
|
||||
jsonWriter.writeComma();
|
||||
}
|
||||
jsonWriter.writeLocalDate(VALUE);
|
||||
}
|
||||
jsonWriter.endArray();
|
||||
|
||||
BH.consume(jsonWriter.getBytes());
|
||||
jsonWriter.close();
|
||||
}
|
||||
|
||||
public void utf16(Blackhole BH) {
|
||||
JSONWriter jsonWriter = JSONWriter.ofUTF16();
|
||||
|
||||
jsonWriter.startArray();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
if (i != 0) {
|
||||
jsonWriter.writeComma();
|
||||
}
|
||||
jsonWriter.writeLocalDate(VALUE);
|
||||
}
|
||||
jsonWriter.endArray();
|
||||
|
||||
BH.consume(jsonWriter.toString());
|
||||
jsonWriter.close();
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.primitves;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONB;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
public class ShortBench {
|
||||
private static final short[] VALUES;
|
||||
|
||||
static {
|
||||
short[] shorts = new short[Short.MAX_VALUE - Short.MIN_VALUE];
|
||||
for (int i = 0; i < shorts.length; i++) {
|
||||
shorts[i] = (short) (Short.MIN_VALUE + i);
|
||||
}
|
||||
VALUES = shorts;
|
||||
}
|
||||
|
||||
public void utf8(Blackhole BH) {
|
||||
JSONWriter jsonWriter = JSONWriter.ofUTF8();
|
||||
jsonWriter.writeAny(VALUES);
|
||||
BH.consume(jsonWriter.getBytes());
|
||||
jsonWriter.close();
|
||||
}
|
||||
|
||||
public void utf16(Blackhole BH) {
|
||||
JSONWriter jsonWriter = JSONWriter.ofUTF16();
|
||||
jsonWriter.writeAny(VALUES);
|
||||
BH.consume(jsonWriter.getBytes());
|
||||
jsonWriter.close();
|
||||
}
|
||||
|
||||
public void bean_jsonBytes(Blackhole BH) {
|
||||
for (int i = 0; i + 10 <= VALUES.length; i += 10) {
|
||||
Bean bean = new Bean();
|
||||
bean.v0 = VALUES[i];
|
||||
bean.v1 = VALUES[i + 1];
|
||||
bean.v2 = VALUES[i + 2];
|
||||
bean.v3 = VALUES[i + 3];
|
||||
bean.v4 = VALUES[i + 4];
|
||||
bean.v5 = VALUES[i + 5];
|
||||
bean.v6 = VALUES[i + 6];
|
||||
bean.v7 = VALUES[i + 7];
|
||||
bean.v8 = VALUES[i + 8];
|
||||
bean.v9 = VALUES[i + 9];
|
||||
byte[] bytes = JSON.toJSONBytes(bean);
|
||||
BH.consume(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void bean_jsonStr(Blackhole BH) {
|
||||
for (int i = 0; i + 10 <= VALUES.length; i += 10) {
|
||||
Bean bean = new Bean();
|
||||
bean.v0 = VALUES[i];
|
||||
bean.v1 = VALUES[i + 1];
|
||||
bean.v2 = VALUES[i + 2];
|
||||
bean.v3 = VALUES[i + 3];
|
||||
bean.v4 = VALUES[i + 4];
|
||||
bean.v5 = VALUES[i + 5];
|
||||
bean.v6 = VALUES[i + 6];
|
||||
bean.v7 = VALUES[i + 7];
|
||||
bean.v8 = VALUES[i + 8];
|
||||
bean.v9 = VALUES[i + 9];
|
||||
String jsonStr = JSON.toJSONString(bean);
|
||||
BH.consume(jsonStr);
|
||||
}
|
||||
}
|
||||
|
||||
public void bean_jsonb(Blackhole BH) {
|
||||
for (int i = 0; i + 10 <= VALUES.length; i += 10) {
|
||||
Bean bean = new Bean();
|
||||
bean.v0 = VALUES[i];
|
||||
bean.v1 = VALUES[i + 1];
|
||||
bean.v2 = VALUES[i + 2];
|
||||
bean.v3 = VALUES[i + 3];
|
||||
bean.v4 = VALUES[i + 4];
|
||||
bean.v5 = VALUES[i + 5];
|
||||
bean.v6 = VALUES[i + 6];
|
||||
bean.v7 = VALUES[i + 7];
|
||||
bean.v8 = VALUES[i + 8];
|
||||
bean.v9 = VALUES[i + 9];
|
||||
byte[] bytes = JSONB.toBytes(bean);
|
||||
BH.consume(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean {
|
||||
public short v0;
|
||||
public short v1;
|
||||
public short v2;
|
||||
public short v3;
|
||||
public short v4;
|
||||
public short v5;
|
||||
public short v6;
|
||||
public short v7;
|
||||
public short v8;
|
||||
public short v9;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.simdjson;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.benchmark.eishay.EishayParseBinary;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class GithubEvents {
|
||||
static final String file = "data/simd-json/github_events.json";
|
||||
static byte[] bytes;
|
||||
static {
|
||||
try (InputStream is = EishayParseBinary.class.getClassLoader().getResourceAsStream(file)) {
|
||||
String str = IOUtils.toString(is, "UTF-8");
|
||||
bytes = str.getBytes();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void fastjson2_parse(Blackhole bh) {
|
||||
bh.consume(JSON.parseArray(bytes));
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.utf8;
|
||||
|
||||
import com.alibaba.fastjson2.util.IOUtils;
|
||||
import com.alibaba.fastjson2.util.JDKUtils;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
||||
|
||||
public class UTF8Encode {
|
||||
static final CacheItem[] CACHE_ITEMS;
|
||||
|
||||
static {
|
||||
final CacheItem[] items = new CacheItem[16];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = new CacheItem();
|
||||
}
|
||||
CACHE_ITEMS = items;
|
||||
}
|
||||
|
||||
static final int CACHE_THRESHOLD = 1024 * 1024 * 4;
|
||||
static final AtomicReferenceFieldUpdater<CacheItem, char[]> CHARS_UPDATER
|
||||
= AtomicReferenceFieldUpdater.newUpdater(CacheItem.class, char[].class, "chars");
|
||||
static final AtomicReferenceFieldUpdater<CacheItem, byte[]> BYTES_UPDATER
|
||||
= AtomicReferenceFieldUpdater.newUpdater(CacheItem.class, byte[].class, "bytes");
|
||||
|
||||
static final class CacheItem {
|
||||
volatile char[] chars;
|
||||
volatile byte[] bytes;
|
||||
}
|
||||
|
||||
static final String STR_CN_SMALL = "規定了四種表";
|
||||
static final String STR0 = "EEE 754規定了四種表示浮點數值的方式:單精確度(32位元)、雙精確度(64位元)、延伸單精確度(43位元以上,很少使用)與延伸雙精確度(79位元以上,通常以80位元實做)。只有32位元模式有強制要求,其他都是選擇性的。大部分程式語言都提供了IEEE浮点数格式與算術,但有些將其列為非必需的。例如,IEEE 754問世之前就有的C語言,現在包括了IEEE算術,但不算作強制要求(C語言的float通常是指IEEE單精確度,而double是指雙精確度)。";
|
||||
static final String STR1 = "ISO/IEC 8859-1:1998, Information technology — 8-bit single-byte coded graphic character sets — Part 1: Latin alphabet No. 1, is part of the ISO/IEC 8859 series of ASCII-based standard character encodings, first edition published in 1987. ISO/IEC 8859-1 encodes what it refers to as \"Latin alphabet no. 1\", consisting of 191 characters from the Latin script. This character-encoding scheme is used throughout the Americas, Western Europe, Oceania, and much of Africa. It is the basis for some popular 8-bit character sets and the first two blocks of characters in Unicode.";
|
||||
|
||||
public void jdk(Blackhole bh) {
|
||||
bh.consume(
|
||||
STR0.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
}
|
||||
|
||||
public void jdk_small(Blackhole bh) {
|
||||
bh.consume(
|
||||
STR_CN_SMALL.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
}
|
||||
|
||||
public void fj(Blackhole bh) {
|
||||
bh.consume(
|
||||
encode(STR0)
|
||||
);
|
||||
}
|
||||
|
||||
public void fj_small(Blackhole bh) {
|
||||
bh.consume(
|
||||
encode(STR_CN_SMALL)
|
||||
);
|
||||
}
|
||||
|
||||
public void jdk_ascii(Blackhole bh) {
|
||||
bh.consume(
|
||||
STR1.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
}
|
||||
|
||||
public void fj_ascii(Blackhole bh) {
|
||||
byte[] utf8 = encode(STR1);
|
||||
bh.consume(utf8);
|
||||
}
|
||||
|
||||
private static byte[] jdk8(String str) {
|
||||
char[] chars = JDKUtils.getCharArray(str);
|
||||
|
||||
int cacheIndex = System.identityHashCode(Thread.currentThread()) & (CACHE_ITEMS.length - 1);
|
||||
CacheItem cacheItem = CACHE_ITEMS[cacheIndex];
|
||||
byte[] bytes = BYTES_UPDATER.getAndSet(cacheItem, null);
|
||||
|
||||
int bufferSize = chars.length * 3;
|
||||
if (bytes == null || bytes.length < bufferSize) {
|
||||
bytes = new byte[bufferSize];
|
||||
}
|
||||
|
||||
int cnt = IOUtils.encodeUTF8(chars, 0, chars.length, bytes, 0);
|
||||
byte[] utf8 = Arrays.copyOf(bytes, cnt);
|
||||
BYTES_UPDATER.lazySet(cacheItem, bytes);
|
||||
return utf8;
|
||||
}
|
||||
|
||||
private static byte[] encode(String str) {
|
||||
if (JDKUtils.JVM_VERSION <= 8 || JDKUtils.STRING_CODER == null) {
|
||||
return jdk8(str);
|
||||
}
|
||||
int coder = JDKUtils.STRING_CODER.applyAsInt(str);
|
||||
byte[] value = JDKUtils.STRING_VALUE.apply(str);
|
||||
|
||||
if (coder == 0) {
|
||||
boolean hasNegative;
|
||||
try {
|
||||
hasNegative = (Boolean) JDKUtils.METHOD_HANDLE_HAS_NEGATIVE.invoke(value, 0, value.length);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (!hasNegative) {
|
||||
return value;
|
||||
}
|
||||
return str.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
int cacheIndex = System.identityHashCode(Thread.currentThread()) & (CACHE_ITEMS.length - 1);
|
||||
CacheItem cacheItem = CACHE_ITEMS[cacheIndex];
|
||||
byte[] bytes = BYTES_UPDATER.getAndSet(cacheItem, null);
|
||||
|
||||
int bufferSize = str.length() * 3;
|
||||
if (bytes == null || bytes.length < bufferSize) {
|
||||
bytes = new byte[bufferSize];
|
||||
}
|
||||
|
||||
int cnt = IOUtils.encodeUTF8(value, 0, value.length, bytes, 0);
|
||||
byte[] utf8 = Arrays.copyOf(bytes, cnt);
|
||||
BYTES_UPDATER.lazySet(cacheItem, bytes);
|
||||
return utf8;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.wast;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class IOUtilsBench {
|
||||
static byte[] bytes;
|
||||
static char[] chars;
|
||||
static String str;
|
||||
|
||||
static {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
buf.append(12345678);
|
||||
}
|
||||
str = buf.toString();
|
||||
bytes = str.getBytes();
|
||||
chars = str.toCharArray();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void digit4(Blackhole bh) throws Throwable {
|
||||
for (int i = 0; i < 1000; i += 8) {
|
||||
bh.consume(com.alibaba.fastjson2.util.IOUtils.digit4(bytes, 0));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(IOUtilsBench.class.getName())
|
||||
.mode(Mode.Throughput)
|
||||
.timeUnit(TimeUnit.MILLISECONDS)
|
||||
.warmupIterations(3)
|
||||
.threads(1)
|
||||
.forks(1)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"as": "AS16509 Amazon.com, Inc.",
|
||||
"city": "Boardman",
|
||||
"country": "United States",
|
||||
"countryCode": "US",
|
||||
"isp": "Amazon",
|
||||
"lat": 45.8696,
|
||||
"lon": -119.688,
|
||||
"org": "Amazon",
|
||||
"query": "54.148.84.95",
|
||||
"region": "OR",
|
||||
"regionName": "Oregon",
|
||||
"status": "success",
|
||||
"timezone": "America\/Los_Angeles",
|
||||
"zip": "97818"
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"clients":[{"about":"中文yH1fix9pXbKEh5fJuly1","address":"中文Nljq0lukStDonHEcVRHE","age":64,"balance":0.44240027590133413,"company":"中文FgeVau3mS5w9mhcWwuKS","emails":["MfNsDmpsUsXpnDzvrcKm","jAyzPlasKbeYAvTdClOi","FODRICnLkoeXkifYBDZW","AIGvokIjTNJjgRQlcGAG","HvwnRvNkYdlVCrbBBZkD","EoaXVUulXKvnguaSuqrz","MjTFZwEgvEbGexOLOUCe","VFXuEiWfszLdGjWpVyXY"],"eyeColor":"BLUE","gender":"MrJ369tihTC7lZNK5bPo","guid":"70a95e90-425e-f2a7-db42-b83c18442df3","id":5917278237879270907,"index":500779379,"isActive":true,"latitude":3.237861088027525,"longitude":28.303947340611323,"name":"pVwnJvTLvrlferKSaG9o","partners":[{"id":-4992443277785453447,"name":"QvqPmFvFeLNggovkrLJLTHMehPHXFv","since":"1917-12-23T06:56:19.5013299Z"},{"id":7414865681841083540,"name":"lomuqksUvvBkkdyOUOfYVDopkTQGMK","since":"1983-12-24T09:34:01.284158669Z"},{"id":8483963072105131018,"name":"LOcRXNwppbCbrKtbnZlEFDFoNaHfAm","since":"1973-06-09T03:42:43.661968037Z"},{"id":-2059367369353171635,"name":"KQZVaVAxxaagquXdlVqaEbirVREPrc","since":"1914-04-26T17:12:57.205244091Z"},{"id":216128505382995309,"name":"bQpPRcRPsmnXSUApCtLoeIoWLFcylD","since":"1925-03-25T00:02:16.950150228Z"},{"id":-6331778364589206153,"name":"TpRJOziKUAgGJlbeleTcHwDgagmits","since":"1987-09-13T01:20:47.997888071Z"},{"id":-3449909979167971348,"name":"wCAsmHghlJNNONapFCDDiDDsixNKTu","since":"1982-10-25T04:05:34.720262937Z"},{"id":-5177986292895188953,"name":"dYhtDCbappBRjNHmUZOFpNyeglbwiw","since":"1919-10-14T10:28:31.669682461Z"},{"id":6239205551293135613,"name":"qUmJvesyiWMIZzBNLIOCjGkLaUMavd","since":"1940-10-14T04:47:37.631870618Z"},{"id":8851381720745793026,"name":"RsYbNUldwNFbAkxIYlemjptpecueDz","since":"1923-03-01T03:26:34.449016475Z"}],"phones":[1554466975,1263898911],"picture":"pVJdkPiSIno4Lr4n6T48xftyqIVnbuOWFkISpRY5gJAS0HDGfNM4Xs5Aw7L0yMS9Pu39coV6V6M11MXspNSMLoBO17CU4pmnrP4X","registered":"1930-06-24","tags":["1LGhuAhMHT","d2CMWFnmKs","I5Kz2sl3ea","nEjMMcLHOG","Wf5vWHhffW","3o5XjSt8bK","403BW3jTeF","Yqo14HhTmq","tOK5V9eaM3","EEFvDelYvP","LAmXdWfKw7","5xZCukg63f","muqvClzcXO","HEVG0HHKXn","5EdKtQZX6D","nVNmXvckwP","5d940ocGOK","7EUFIBtKW0","TGL1fImxEw","K9TnndP7Or","aA8GoXyO7W","a3RMQL8a51","7Y7RyeHXVs"]}]}
|
@ -1,102 +0,0 @@
|
||||
{
|
||||
"name1000":0,
|
||||
"name1001":1,
|
||||
"name1002":2,
|
||||
"name1003":3,
|
||||
"name1004":4,
|
||||
"name1005":5,
|
||||
"name1006":6,
|
||||
"name1007":7,
|
||||
"name1008":8,
|
||||
"name1009":9,
|
||||
"name1010":10,
|
||||
"name1011":11,
|
||||
"name1012":12,
|
||||
"name1013":13,
|
||||
"name1014":14,
|
||||
"name1015":15,
|
||||
"name1016":16,
|
||||
"name1017":17,
|
||||
"name1018":18,
|
||||
"name1019":19,
|
||||
"name1020":20,
|
||||
"name1021":21,
|
||||
"name1022":22,
|
||||
"name1023":23,
|
||||
"name1024":24,
|
||||
"name1025":25,
|
||||
"name1026":26,
|
||||
"name1027":27,
|
||||
"name1028":28,
|
||||
"name1029":29,
|
||||
"name1030":30,
|
||||
"name1031":31,
|
||||
"name1032":32,
|
||||
"name1033":33,
|
||||
"name1034":34,
|
||||
"name1035":35,
|
||||
"name1036":36,
|
||||
"name1037":37,
|
||||
"name1038":38,
|
||||
"name1039":39,
|
||||
"name1040":40,
|
||||
"name1041":41,
|
||||
"name1042":42,
|
||||
"name1043":43,
|
||||
"name1044":44,
|
||||
"name1045":45,
|
||||
"name1046":46,
|
||||
"name1047":47,
|
||||
"name1048":48,
|
||||
"name1049":49,
|
||||
"name1050":50,
|
||||
"name1051":51,
|
||||
"name1052":52,
|
||||
"name1053":53,
|
||||
"name1054":54,
|
||||
"name1055":55,
|
||||
"name1056":56,
|
||||
"name1057":57,
|
||||
"name1058":58,
|
||||
"name1059":59,
|
||||
"name1060":60,
|
||||
"name1061":61,
|
||||
"name1062":62,
|
||||
"name1063":63,
|
||||
"name1064":64,
|
||||
"name1065":65,
|
||||
"name1066":66,
|
||||
"name1067":67,
|
||||
"name1068":68,
|
||||
"name1069":69,
|
||||
"name1070":70,
|
||||
"name1071":71,
|
||||
"name1072":72,
|
||||
"name1073":73,
|
||||
"name1074":74,
|
||||
"name1075":75,
|
||||
"name1076":76,
|
||||
"name1077":77,
|
||||
"name1078":78,
|
||||
"name1079":79,
|
||||
"name1080":80,
|
||||
"name1081":81,
|
||||
"name1082":82,
|
||||
"name1083":83,
|
||||
"name1084":84,
|
||||
"name1085":85,
|
||||
"name1086":86,
|
||||
"name1087":87,
|
||||
"name1088":88,
|
||||
"name1089":89,
|
||||
"name1090":90,
|
||||
"name1091":91,
|
||||
"name1092":92,
|
||||
"name1093":93,
|
||||
"name1094":94,
|
||||
"name1095":95,
|
||||
"name1096":96,
|
||||
"name1097":97,
|
||||
"name1098":98,
|
||||
"name1099":99
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,5 @@
|
||||
package com.alibaba.fastjson2.benchmark;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.alibaba.fastjson2.benchmark.JMH.BH;
|
||||
|
||||
public class BytesAsciiCheckTest {
|
||||
@ -34,19 +32,6 @@ public class BytesAsciiCheckTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void isASCII() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
benchmark.isASCII(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("BytesAsciiCheck-isASCII : " + millis);
|
||||
|
||||
// zulu17.40.19 : 118
|
||||
}
|
||||
}
|
||||
|
||||
public static void direct() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
@ -60,35 +45,23 @@ public class BytesAsciiCheckTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void isLatin1() throws Throwable {
|
||||
public static void direct8() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
benchmark.isLatin1(BH);
|
||||
benchmark.direct8(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("BytesAsciiCheck-isASCII_chars : " + millis);
|
||||
System.out.println("BytesAsciiCheck-direct8 : " + millis);
|
||||
|
||||
// zulu17.40.19 : 478
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
// System.out.println(Integer.toHexString(-1) + "\t" + Integer.toBinaryString(-1));
|
||||
// System.out.println(Integer.toHexString(-2) + "\t" + Integer.toBinaryString(-2));
|
||||
// System.out.println(Integer.toHexString(Integer.MIN_VALUE) + "\t" + Integer.toBinaryString(Integer.MIN_VALUE));
|
||||
// System.out.println(Integer.toHexString(Integer.MIN_VALUE + 1) + "\t" + Integer.toBinaryString(Integer.MIN_VALUE + 1));
|
||||
long x = 0x8080808080808080L;
|
||||
System.out.println(Long.toBinaryString(x));
|
||||
System.out.println(x);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// handler();
|
||||
// lambda();
|
||||
lambda();
|
||||
// direct();
|
||||
isLatin1();
|
||||
// isASCII();
|
||||
// direct8();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import static com.alibaba.fastjson2.benchmark.JMH.BH;
|
||||
|
||||
public class CSVBankTest {
|
||||
static final CSVBank benchmark = new CSVBank();
|
||||
static final int LOOP = 10000;
|
||||
static final int LOOP = 1000;
|
||||
|
||||
public static void fastjson2() {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
@ -16,7 +16,7 @@ public class CSVBankTest {
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.68.0.21 : 213
|
||||
// zulu11.62.17 : 148
|
||||
// zulu17.40.19 : 150 1746 1639
|
||||
// zulu17.40.19 : 150
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ public class CSVBankTest {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
fastjson2();
|
||||
// univocity();
|
||||
// fastjson2();
|
||||
univocity();
|
||||
// cainiao();
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ public class CSVPersonTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.68.0.21 : 3621 3270 2788 2424 2431 2123
|
||||
// zulu11.62.17 : 2576 1848 2155 1567 1522 1307 1769 1382
|
||||
// zulu17.40.19 : 3501 3134 2586 2788 2733 2682 2494 2163
|
||||
// zulu8.68.0.21 : 3621 3270 2788 2424 2431
|
||||
// zulu11.62.17 : 2576 1848 2155 1567 1522
|
||||
// zulu17.40.19 : 3501 3134 2586 2788
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,53 +1,14 @@
|
||||
package com.alibaba.fastjson2.benchmark;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class GenReport {
|
||||
static final Map<String, String> specs = new HashMap<>();
|
||||
static final Map<String, String> cases = new HashMap<>();
|
||||
static {
|
||||
specs.put("orangepi5p", "http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html");
|
||||
specs.put("orangepi_aipro", "http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html");
|
||||
specs.put("aliyun_ecs.g8y.large", "https://www.alibabacloud.com/zh/product/ecs/g8y");
|
||||
specs.put("aliyun_ecs.c8i.large", "https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i");
|
||||
specs.put("aws_ecs.c7g.large", "https://aws.amazon.com/ec2/instance-types/c7g/");
|
||||
|
||||
cases.put("EishayFuryCompatibleWrite", "这个场景是JSONB格式和Fury CompatibleMode序列化性能比较。基于KeyValue的映射,对增加和删除字段的序列化结构都能有很好的兼容性。");
|
||||
cases.put("EishayFuryCompatibleParse", "这个场景是JSONB格式和Fury CompatibleMode反序列化性能比较。基于KeyValue的映射,对增加和删除字段的序列化结构都能有很好的兼容性。");
|
||||
|
||||
cases.put("EishayWriteBinary", "这个场景是二进制序列化比较,JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较,用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较");
|
||||
cases.put("EishayParseBinary", "这个场景是二进制反序列化比较,JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较,用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较");
|
||||
|
||||
cases.put("EishayWriteBinaryAutoType", "这个场景是带类型信息二进制序列化比较,JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较,用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较");
|
||||
cases.put("EishayParseBinaryAutoType", "这个场景是带类型信息二进制反序列化比较,JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较,用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较");
|
||||
|
||||
cases.put("EishayWriteBinaryArrayMapping", "这个场景是二进制序列化比较,JSONB格式(基于字段顺序映射)、kryo、protobuf的比较");
|
||||
cases.put("EishayParseBinaryArrayMapping", "这个场景是二进制反序列化比较,JSONB格式(基于字段顺序映射)、kryo、protobuf的比较");
|
||||
|
||||
cases.put("EishayParseString", "这个场景是将没有格式化的JSON字符串反序列化为JavaBean对象,是最常用的场景,这个是fastjson1的强项。");
|
||||
cases.put("EishayParseStringPretty", "这个场景是将格式化过的JSON字符串反序列化为JavaBean对象");
|
||||
cases.put("EishayParseTreeString", "这个场景是将没有格式化的JSON字符串解析为JSONObject或者HashMap,不涉及绑定JavaBean对象。");
|
||||
cases.put("EishayParseTreeStringPretty", "这个场景是将格式化过的字符串解析为JSONObject或者HashMap,不涉及绑定JavaBean对象。");
|
||||
|
||||
cases.put("EishayParseUTF8Bytes", "这个场景是将没有格式化的JSON字符串UTF8编码的byte[]数组反序列化为JavaBean对象,是最常用的场景,这个是fastjson1的强项。");
|
||||
cases.put("EishayParseUTF8BytesPretty", "这个场景是将格式化过的JSON字符串UTF8编码的byte[]数组反序列化为JavaBean对象");
|
||||
cases.put("EishayParseTreeUTF8Bytes", "这个场景是将没有格式化的JSON字符串UTF8编码的byte[]数组反序列化解析为JSONObject或者HashMap,不涉及绑定JavaBean对象。");
|
||||
cases.put("EishayParseTreeUTF8BytesPretty", "这个场景是将格式化过的字符串UTF8编码的byte[]数组反序列化解析为JSONObject或者HashMap,不涉及绑定JavaBean对象。");
|
||||
|
||||
cases.put("EishayWriteString", "这个场景是将JavaBean对象序列化为字符串");
|
||||
cases.put("EishayWriteUTF8Bytes", "这个场景是将JavaBean对象序列化为UTF8编码的Bytes");
|
||||
cases.put("EishayWriteStringTree", "这个场景是将JSONObject或者Map序列化为字符串");
|
||||
cases.put("EishayWriteUTF8BytesTree", "这个场景是将JSONObject或者Map序列化为UTF8编码的Bytes");
|
||||
}
|
||||
|
||||
public void gen() throws Exception {
|
||||
File dir = new File("/Users/wenshao/Work/git/fastjson2/docs/benchmark/");
|
||||
File file = new File(dir, "benchmark_" + JSON.VERSION + "_raw.md");
|
||||
File outFile = new File(dir, "benchmark_" + JSON.VERSION + ".md");
|
||||
File file = new File(dir, "benchmark_2.0.38_raw.md");
|
||||
File outFile = new File(dir, "benchmark_2.0.38.md");
|
||||
|
||||
Map<String, BenchmarkResult> benchResults = new LinkedHashMap<>();
|
||||
|
||||
@ -77,17 +38,7 @@ public class GenReport {
|
||||
PrintStream out = new PrintStream(new FileOutputStream(outFile));
|
||||
int h1 = 0;
|
||||
for (BenchmarkResult benchmarkResult : benchResults.values()) {
|
||||
benchmarkResult.libraryResults.remove("jsonbValid"); // skip jsonbValid
|
||||
|
||||
if (benchmarkResult.libraryResults.size() == 2) {
|
||||
LibResult fury = benchmarkResult.libraryResults.get("fury");
|
||||
LibResult jsonb = benchmarkResult.libraryResults.get("jsonb");
|
||||
if (fury != null && jsonb != null) {
|
||||
benchmarkResult.libraryResults.clear();
|
||||
benchmarkResult.libraryResults.put("jsonb", jsonb);
|
||||
benchmarkResult.libraryResults.put("fury", fury);
|
||||
}
|
||||
} else if (benchmarkResult.libraryResults.size() == 4) {
|
||||
if (benchmarkResult.libraryResults.size() == 4) {
|
||||
LibResult fastjson2 = benchmarkResult.libraryResults.get("fastjson2");
|
||||
LibResult fastjson1 = benchmarkResult.libraryResults.get("fastjson1");
|
||||
LibResult jackson = benchmarkResult.libraryResults.get("jackson");
|
||||
@ -169,14 +120,7 @@ public class GenReport {
|
||||
}
|
||||
}
|
||||
|
||||
String code = "https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/" + benchmarkResult.benchmarkCase + ".java";
|
||||
out.println("## " + (++h1) + ". [" + benchmarkResult.benchmarkCase + "](" + code + ")");
|
||||
String desc = cases.get(benchmarkResult.benchmarkCase);
|
||||
if (desc != null) {
|
||||
out.println(desc);
|
||||
}
|
||||
|
||||
out.println();
|
||||
out.println("## " + (++h1) + " " + benchmarkResult.benchmarkCase);
|
||||
|
||||
LibResult firLib = benchmarkResult.libraryResults.values().iterator().next();
|
||||
Set<String> jdks = firLib.scores.keySet();
|
||||
@ -209,26 +153,13 @@ public class GenReport {
|
||||
String ecs = jdk.substring(0, p);
|
||||
|
||||
if (eccWrited.add(ecs)) {
|
||||
String link = specs.get(ecs);
|
||||
if (link == null) {
|
||||
out.print(ecs);
|
||||
} else {
|
||||
out.print('[');
|
||||
out.print(ecs);
|
||||
out.print("](");
|
||||
out.print(link);
|
||||
out.print(')');
|
||||
}
|
||||
out.print(ecs);
|
||||
}
|
||||
|
||||
out.print(" | ");
|
||||
String jdkinfo = jdk.substring(p + 1);
|
||||
if (jdkinfo.startsWith("graalvm-jdk-")) {
|
||||
jdkinfo = "graalvm_" + jdkinfo.substring("graalvm-jdk-".length());
|
||||
} else if (jdkinfo.startsWith("zulu21.0.57")) {
|
||||
jdkinfo = "zulu21.0.57";
|
||||
} else if (jdkinfo.startsWith("zulu21.32.17")) {
|
||||
jdkinfo = "zulu21.32.17";
|
||||
}
|
||||
out.print(jdkinfo);
|
||||
}
|
||||
@ -249,6 +180,49 @@ public class GenReport {
|
||||
}
|
||||
|
||||
out.println();
|
||||
|
||||
LinkedHashMap<String, String[]> graalvm17_jdks = new LinkedHashMap<>();
|
||||
String jdk17 = null, graalvm17 = null;
|
||||
String jdk17_info = null, graalvm17_info = null;
|
||||
for (String jdk : jdks) {
|
||||
int p = jdk.indexOf('-');
|
||||
if (p == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String ecs = jdk.substring(0, p);
|
||||
String[] ecs_jdk17s = graalvm17_jdks.get(ecs);
|
||||
if (ecs_jdk17s == null) {
|
||||
ecs_jdk17s = new String[2];
|
||||
graalvm17_jdks.put(ecs, ecs_jdk17s);
|
||||
}
|
||||
|
||||
String jdkinfo = jdk.substring(p + 1);
|
||||
if (jdkinfo.startsWith("jdk-17.")) {
|
||||
jdk17 = jdk;
|
||||
jdk17_info = jdkinfo;
|
||||
ecs_jdk17s[0] = jdk;
|
||||
} else if (jdkinfo.startsWith("graalvm-jdk-17.")) {
|
||||
graalvm17 = jdk;
|
||||
graalvm17_info = jdkinfo;
|
||||
ecs_jdk17s[1] = jdk;
|
||||
}
|
||||
}
|
||||
|
||||
if (jdk17 != null && graalvm17 != null) {
|
||||
out.println();
|
||||
out.println("### " + h1 + ".1 jdk17 vs graalvm17");
|
||||
out.println("| ecs | library | " + jdk17_info + " | " + graalvm17_info + " | delta |");
|
||||
out.println("|-----|-----|-----|-----|-----|");
|
||||
for (LibResult libResult : benchmarkResult.libraryResults.values()) {
|
||||
for (Map.Entry<String, String[]> entry : graalvm17_jdks.entrySet()) {
|
||||
Double score_jdk17 = libResult.scores.get(entry.getValue()[0]);
|
||||
Double score_graalvm17 = libResult.scores.get(entry.getValue()[1]);
|
||||
double percent = (score_graalvm17 - score_jdk17) / score_jdk17;
|
||||
out.println("| " + entry.getKey() + " | " + libResult.library + " | " + score_jdk17 + " | " + score_graalvm17 + " | " + new DecimalFormat("#,##0.##%").format(percent) + " |");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
@ -282,7 +256,6 @@ public class GenReport {
|
||||
static class DocReader
|
||||
implements Closeable {
|
||||
BufferedReader reader;
|
||||
int lines;
|
||||
|
||||
public DocReader(File file) throws IOException {
|
||||
this.reader = new BufferedReader(new FileReader(file));
|
||||
@ -295,10 +268,8 @@ public class GenReport {
|
||||
|
||||
public Block readBlock() throws Exception {
|
||||
String line = reader.readLine();
|
||||
lines++;
|
||||
while (line != null && line.trim().isEmpty()) {
|
||||
line = reader.readLine();
|
||||
lines++;
|
||||
}
|
||||
|
||||
if (line == null || !line.startsWith("#")) {
|
||||
@ -309,14 +280,12 @@ public class GenReport {
|
||||
block.jdk = line.substring(1).trim();
|
||||
|
||||
line = reader.readLine();
|
||||
lines++;
|
||||
if (!line.startsWith("```")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
do {
|
||||
line = reader.readLine();
|
||||
lines++;
|
||||
} while (line.isEmpty());
|
||||
|
||||
if (line.startsWith("```")) {
|
||||
@ -329,7 +298,6 @@ public class GenReport {
|
||||
|
||||
while (true) {
|
||||
line = reader.readLine();
|
||||
lines++;
|
||||
if (line.startsWith("```")) {
|
||||
break;
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ public class KryoTest {
|
||||
Kryo kryo = new Kryo();
|
||||
Output output = new Output(1024, -1);
|
||||
//
|
||||
// static org.apache.fury.ThreadSafeFury fury = org.apache.fury.Fury.builder()
|
||||
// .withLanguage(org.apache.fury.Language.JAVA)
|
||||
// static io.fury.ThreadSafeFury fury = io.fury.Fury.builder()
|
||||
// .withLanguage(io.fury.Language.JAVA)
|
||||
// .withReferenceTracking(true)
|
||||
// .disableSecureMode()
|
||||
// .withCompatibleMode(org.apache.fury.serializers.CompatibleMode.COMPATIBLE)
|
||||
// .withCompatibleMode(io.fury.serializers.CompatibleMode.COMPATIBLE)
|
||||
// .buildThreadSafeFury();
|
||||
|
||||
@Test
|
||||
|
@ -1,86 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark;
|
||||
|
||||
import static com.alibaba.fastjson2.benchmark.JMH.BH;
|
||||
|
||||
public class Name8Test {
|
||||
static final int LOOP = 1_000_000;
|
||||
static final Name8 benchmark = new Name8();
|
||||
|
||||
public static void fastjson2() {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.fastjson2(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.70.0.23 :
|
||||
// zulu11.64.19 : 5030
|
||||
// zulu17.42.19 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastjson1() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.fastjson1(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson1 millis : " + millis);
|
||||
// zulu8.70.0.23 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void jackson() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.jackson(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("jackson millis : " + millis);
|
||||
// zulu8.70.0.23 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void wastjson() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.wastjson(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayParseString-wastjson millis : " + millis);
|
||||
// zulu8.70.0.23 :
|
||||
// zulu11.64.19 :
|
||||
// zulu17.42.19 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void gson() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.gson(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayParseString-gson millis : " + millis);
|
||||
// zulu8.70.0.23 :
|
||||
// zulu11.64.19 :
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
fastjson2();
|
||||
// jackson();
|
||||
// fastjson1();
|
||||
// gson();
|
||||
// wastjson();
|
||||
}
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package com.alibaba.fastjson2.benchmark;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -10,20 +8,16 @@ import java.util.Map;
|
||||
|
||||
public class ReadResult {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String version = JSON.VERSION;
|
||||
File outFile = new File("/Users/wenshao/Work/git/fastjson2/docs/benchmark/benchmark_" + version + "_raw.md");
|
||||
File outFile = new File("/Users/wenshao/Work/git/fastjson2/docs/benchmark/benchmark_2.0.38_raw.md");
|
||||
// File file = new File("/Users/wenshao/Downloads/result_2.0.25.out");
|
||||
|
||||
Map<String, String> files = new LinkedHashMap<>();
|
||||
files.put("aliyun_ecs.c8a.large", "/Users/wenshao/Downloads/result_" + version + "_g8a.out");
|
||||
files.put("aliyun_ecs.c8i.large", "/Users/wenshao/Downloads/result_" + version + "_g8i.out");
|
||||
files.put("aliyun_ecs.c8i.large", "/Users/wenshao/Downloads/result_2.0.38_g8i.out");
|
||||
// files.put("aliyun_ecs.g7.large", "/Users/wenshao/Downloads/result_2.0.33_g7.out");
|
||||
files.put("aliyun_ecs.g8y.large", "/Users/wenshao/Downloads/result_" + version + "_g8y.out");
|
||||
// files.put("aws_ecs.c6g.large", "/Users/wenshao/Downloads/result_2.0.41_aws_c6g.out");
|
||||
// files.put("aws_ecs.c7g.large", "/Users/wenshao/Downloads/result_" + version + "_aws_c7g.out");
|
||||
files.put("orangepi5p", "/Users/wenshao/Downloads/result_" + version + "_orangepi5.out");
|
||||
files.put("orangepi_aipro", "/Users/wenshao/Downloads/result_" + version + "_orangepi_aipro.out");
|
||||
files.put("MacBookM1Pro", "/Users/wenshao/Downloads/result_" + version + "_applem1pro.out");
|
||||
files.put("aliyun_ecs.c8y.large", "/Users/wenshao/Downloads/result_2.0.38_g8y.out");
|
||||
// files.put("aws_ecs.c6g.large", "/Users/wenshao/Downloads/result_2.0.33_aws_c6g.out");
|
||||
// files.put("aws_ecs.c7g.large", "/Users/wenshao/Downloads/result_2.0.33_aws_c7g.out");
|
||||
files.put("orangepi5p", "/Users/wenshao/Downloads/result_2.0.38_orangepi5.out");
|
||||
|
||||
PrintStream out = new PrintStream(new FileOutputStream(outFile));
|
||||
files.forEach((k, v) -> {
|
||||
@ -105,12 +99,6 @@ public class ReadResult {
|
||||
vm = "graalvm-ce-1" + vm.substring("graalvm-ce-java1".length());
|
||||
} else if (vm.startsWith("graalvm-ee-java1")) {
|
||||
vm = "graalvm-ee-1" + vm.substring("graalvm-ee-java1".length());
|
||||
} else if (vm.startsWith("zulu8.68.0.21")) {
|
||||
vm = "zulu8.68.0.21";
|
||||
} else if (vm.startsWith("zulu8.82.0.21")) {
|
||||
vm = "zulu8.82.0.21";
|
||||
} else if (vm.startsWith("zulu17.54.21")) {
|
||||
vm = "zulu17.54.21";
|
||||
}
|
||||
String title = "# " + spec + "-" + vm;
|
||||
blockLines.add(title);
|
||||
|
@ -14,9 +14,9 @@ public class TaobaoH5ApiTreeTest {
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("TaobaoH5ApiTree-fastjson2 : " + millis);
|
||||
|
||||
// zulu8.62.0.19 : 1940 1592 1423 1168
|
||||
// zulu11.52.13 : 2836 1701 2257 1194
|
||||
// zulu17.32.13 : 1516 1240
|
||||
// zulu8.62.0.19 : 1940 1592 1423
|
||||
// zulu11.52.13 : 2836 1701 2257
|
||||
// zulu17.32.13 : 1516
|
||||
// zulu18.28.13 : 1527
|
||||
// zulu19.0.47 :
|
||||
// corretto-8 :
|
||||
|
@ -16,47 +16,14 @@ public class AlongParseBinaryArrayMappingTest {
|
||||
benchmark.jsonb(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongParseBinaryArrayMapping-jsonb millis : " + millis);
|
||||
System.out.println("AlongParseBinaryArrayMapping-fastjson2_jsonb millis : " + millis);
|
||||
// zulu8.68.0.21 : 2928 2887 2826 2806 2754 2693 1876
|
||||
// zulu11.52.13 : 2484 2170 1916 1911 1892 1879 1876 1845 1756
|
||||
// zulu17.32.13 : 2601 2457 1691 1593 1334
|
||||
}
|
||||
}
|
||||
|
||||
public static void jsonbFeatures() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.jsonbFeatures(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongParseBinaryArrayMapping-jsonbFeatures millis : " + millis);
|
||||
// zulu8.68.0.21 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 : 1252
|
||||
}
|
||||
}
|
||||
|
||||
public static void fury() throws Exception {
|
||||
System.out.println("AlongParseBinaryArrayMapping-fury size " + AlongParseBinaryArrayMapping.furyBytes.length); // 449
|
||||
System.out.println();
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.fury(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongParseBinaryArrayMapping-fury millis : " + millis);
|
||||
// zulu8.68.0.21 : 2050
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 : 1587 1154
|
||||
// zulu17.32.13 : 2601 2457 1691
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
jsonb();
|
||||
// jsonbFeatures();
|
||||
// fury();
|
||||
}
|
||||
}
|
||||
|
@ -4,93 +4,37 @@ import static com.alibaba.fastjson2.benchmark.JMH.BH;
|
||||
|
||||
public class AlongWriteBinaryArrayMappingTest {
|
||||
static final AlongWriteBinaryArrayMapping benchmark = new AlongWriteBinaryArrayMapping();
|
||||
static final int LOOP_COUNT = 10_000_000;
|
||||
|
||||
public static void jsonb() throws Exception {
|
||||
// 255
|
||||
System.out.println("AlongWriteBinaryArrayMapping-jsonb size : " + benchmark.jsonbSize());
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
for (int i = 0; i < 10_000_000; ++i) {
|
||||
benchmark.jsonb(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongWriteBinaryArrayMapping-fastjson2_jsonb millis : " + millis);
|
||||
// zulu8.68.0.21 : 1474 945
|
||||
// zulu11.52.13 : 1477 1480 1470 1389 1361 1009
|
||||
// zulu17.32.13 : 3126 2888 2736 2564 1674 1404 1054
|
||||
}
|
||||
}
|
||||
|
||||
public static void jsonbFeatures() throws Exception {
|
||||
// 255
|
||||
// System.out.println("AlongWriteBinaryArrayMapping-jsonb size : " + benchmark.jsonbSize());
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
benchmark.jsonbFeatures(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongWriteBinaryArrayMapping-fastjson2_jsonb_features millis : " + millis);
|
||||
// zulu8.68.0.21 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 : 3126 2888 2736 2564 1674 1404 1785 1340 1060
|
||||
// zulu11.52.13 : 1477 1480 1470 1389 1361
|
||||
// zulu17.32.13 : 3126 2888 2736 2564 1674
|
||||
}
|
||||
}
|
||||
|
||||
public static void json() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
for (int i = 0; i < 1_000_000; ++i) {
|
||||
benchmark.json(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongWriteBinaryArrayMapping-fastjson2_jsonb millis : " + millis);
|
||||
// zulu8.68.0.21 :
|
||||
// zulu11.52.13 : 1046 1007 1004
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void jsonStr() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
benchmark.jsonStr(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongWriteBinaryArrayMapping-fastjson2_jsonStr millis : " + millis);
|
||||
// zulu8.68.0.21 :
|
||||
// zulu11.52.13 : 1032
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void fury() throws Exception {
|
||||
// 449
|
||||
System.out.println("AlongWriteBinaryArrayMapping-fury size : " + benchmark.furySize());
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
benchmark.fury(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("AlongWriteBinaryArrayMapping-fury millis : " + millis);
|
||||
// size 379
|
||||
// zulu8.68.0.21 :
|
||||
// zulu11.52.13 : 2086 967
|
||||
// zulu11.52.13 : 1046
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// jsonb();
|
||||
jsonbFeatures();
|
||||
// json();
|
||||
// jsonStr();
|
||||
// fury();
|
||||
json();
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ public class EishayFuryCompatibleParseTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayFuryParse-fastjson2_jsonb millis : " + millis);
|
||||
// zulu8.68.0.21_AppleM1Max : 3824 3849 3678 3441 3315
|
||||
// zulu11.62.17_AppleM1Max : 3023 3196 3174 2888 3227
|
||||
// zulu17.40.19_AppleM1Max : 3109 3074 3140 2875 3004 2985 2808
|
||||
// zulu8.68.0.21_AppleM1Max : 3824 3849 3678 3441
|
||||
// zulu11.62.17_AppleM1Max : 3023 3196 3174 2888
|
||||
// zulu17.40.19_AppleM1Max : 3109 3074 3140 2875 3004 2985
|
||||
// oracle-jdk-17.0.6 3052
|
||||
|
||||
// jdk1.8.0_361_x86_i9 7343
|
||||
|
@ -15,14 +15,16 @@ public class EishayFuryCompatibleWriteTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayFuryCompatibleWrite-jsonb millis : " + millis);
|
||||
// zulu8.68.0.21_AppleM1Max : 3839 3798 3763 3145 2129 1722
|
||||
// zulu11.62.17_AppleM1Max : 3327 3244 3310 3085 2907 1836 1449
|
||||
// zulu17.40.19_AppleM1Max : 3287 3256 3321 3296 3257 3390 1842 1474
|
||||
// zulu8.68.0.21_AppleM1Max : 3839 3798 3763 3145
|
||||
// zulu11.62.17_AppleM1Max : 3327 3244 3310 3085 2907
|
||||
// zulu17.40.19_AppleM1Max : 3287 3256 3321 3296 3257 3390
|
||||
|
||||
// graalvm-17.0.7 : 2628
|
||||
}
|
||||
}
|
||||
|
||||
public static void fury() throws Exception {
|
||||
System.out.println("fury size " + benchmark.furySize()); // 661 502
|
||||
System.out.println("fury size " + benchmark.furySize()); // 661
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
@ -30,9 +32,9 @@ public class EishayFuryCompatibleWriteTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayFuryCompatibleWrite-fury millis : " + millis);
|
||||
// zulu8.68.0.21_AppleM1Max : 2644 3018 2448
|
||||
// zulu11.62.17_AppleM1Max : 2270 2510 1652
|
||||
// zulu17.40.19_AppleM1Max : 2296 2319 2293 1698
|
||||
// zulu8.68.0.21_AppleM1Max : 2644 3018
|
||||
// zulu11.62.17_AppleM1Max : 2270 2510
|
||||
// zulu17.40.19_AppleM1Max : 2296 2319 2293
|
||||
|
||||
// jdk1.8.0_361_x86_i9 5279
|
||||
// jdk17.0.6_x86_i9 5910
|
||||
|
@ -41,7 +41,7 @@ public class EishayFuryParseTest {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// jsonb();
|
||||
fury();
|
||||
jsonb();
|
||||
// fury();
|
||||
}
|
||||
}
|
||||
|
@ -56,26 +56,25 @@ public class EishayParseBinaryArrayMappingTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void fury() throws Exception {
|
||||
System.out.println("fury size " + EishayParseBinaryArrayMapping.furyBytes.length); // 235
|
||||
public static void fastjson2UTF8Bytes() throws Exception {
|
||||
System.out.println("fastjson2UTF8Bytes size " + EishayParseBinaryArrayMapping.fastjson2UTF8Bytes.length); // 235
|
||||
System.out.println();
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.protobuf(BH);
|
||||
benchmark.fastjson2UTF8Bytes(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayParseBinaryArrayMapping-protobuf millis : " + millis);
|
||||
// zulu8.68.0.21 : 4660
|
||||
// zulu11.52.13 : 4475
|
||||
// zulu17.32.13 : 4357
|
||||
System.out.println("EishayParseBinaryArrayMapping-fastjson2UTF8Bytes millis : " + millis);
|
||||
// zulu8.68.0.21 : 4655
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
jsonb();
|
||||
// fury();
|
||||
// kryo();
|
||||
// protobuf();
|
||||
// fastjson2UTF8Bytes();
|
||||
|
@ -5,15 +5,13 @@ import static com.alibaba.fastjson2.benchmark.JMH.BH;
|
||||
public class EishayParseBinaryTest {
|
||||
static final EishayParseBinary benchmark = new EishayParseBinary();
|
||||
|
||||
static final int LOOP = 1000 * 1000 * 10;
|
||||
|
||||
public static void jsonb() throws Exception {
|
||||
System.out.println("jsonb size " + EishayParseBinary.fastjson2JSONBBytes.length); // 348
|
||||
System.out.println();
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.jsonb(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
@ -28,30 +26,13 @@ public class EishayParseBinaryTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void jsonbValid() throws Exception {
|
||||
System.out.println("jsonb size " + EishayParseBinary.fastjson2JSONBBytes.length); // 348
|
||||
System.out.println();
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.jsonbValid(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayParseBinary-jsonbValid millis : " + millis);
|
||||
// zulu8.58.0.13 : 1836 1743 1635
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void kryo() throws Exception {
|
||||
System.out.println("kryo size " + EishayParseBinary.kryoBytes.length); //
|
||||
System.out.println();
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.kryo(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
@ -62,27 +43,8 @@ public class EishayParseBinaryTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastjson2UTF8Bytes() throws Exception {
|
||||
System.out.println("fastjson2UTF8Bytes size " + EishayParseBinary.fastjson2UTF8Bytes.length); //
|
||||
System.out.println();
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.fastjson2UTF8Bytes(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayParseBinary-fastjson2UTF8Bytes millis : " + millis);
|
||||
// zulu8.58.0.13 : 4259
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 : 3840
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// jsonb();
|
||||
// jsonbValid();
|
||||
jsonb();
|
||||
// kryo();
|
||||
fastjson2UTF8Bytes();
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ public class EishayParseStringTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.70.0.23 : 5569 5630 4435 4199 3851 3791
|
||||
// zulu11.64.19 : 5022 5033 3754 3579
|
||||
// zulu17.42.19 : 5377 5193 5222 5154 5116 5083 4987 4079 3751
|
||||
// zulu8.70.0.23 : 5569 5630 4435
|
||||
// zulu11.64.19 : 5022 5033 3754
|
||||
// zulu17.42.19 : 5377 5193 5222 5154 5116 5083 4987 4079
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,30 +6,34 @@ public class EishayParseTreeStringTest {
|
||||
static final Blackhole BH = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.");
|
||||
static final EishayParseTreeString benchmark = new EishayParseTreeString();
|
||||
|
||||
public static void fastjson2() {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.fastjson2(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.62.0.19 : 666 765 727 725
|
||||
// zulu11.52.13 : 821 688 667
|
||||
// zulu17.32.13 : 601 666
|
||||
// zulu18.28.13 : 598 667
|
||||
// zulu19.0.75 : 673
|
||||
// corretto-8 :
|
||||
// corretto-11 :
|
||||
// corretto-17 :
|
||||
// corretto-18 :
|
||||
// oracle-jdk-17.0.4 :
|
||||
// oracle-jdk-18.0.2 :
|
||||
// ibm-aarch64_mac_11.0.15_10 : 1240
|
||||
// ibm-aarch64_mac_17.0.3_7 : 1311
|
||||
public static void fastjson2_test() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
fastjson2();
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastjson2() {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.fastjson2(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.62.0.19 : 666 765
|
||||
// zulu11.52.13 : 821 688 667
|
||||
// zulu17.32.13 : 601 666
|
||||
// zulu18.28.13 : 598 667
|
||||
// zulu19.0.75 : 673
|
||||
// corretto-8 :
|
||||
// corretto-11 :
|
||||
// corretto-17 :
|
||||
// corretto-18 :
|
||||
// oracle-jdk-17.0.4 :
|
||||
// oracle-jdk-18.0.2 :
|
||||
// ibm-aarch64_mac_11.0.15_10 : 1240
|
||||
// ibm-aarch64_mac_17.0.3_7 : 1311
|
||||
}
|
||||
|
||||
public static void jackson_test() throws Exception {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
jackson();
|
||||
@ -109,7 +113,7 @@ public class EishayParseTreeStringTest {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
fastjson2();
|
||||
fastjson2_test();
|
||||
// gson_test();
|
||||
// jackson_test();
|
||||
// wastjson_test();
|
||||
|
@ -6,32 +6,18 @@ public class EishayParseUTF8BytesTest {
|
||||
static final EishayParseUTF8Bytes benchmark = new EishayParseUTF8Bytes();
|
||||
|
||||
public static void fastjson2() {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.fastjson2(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.62.0.19 : 703 746 710 706 700 682 717 698 526 500 474 445 425
|
||||
// zulu11.52.13 : 579 565 552 541 554 553 554 538 420 424 434 370
|
||||
// zulu17.40.19 : 600 604 597 593 578 567 447 420 380 379
|
||||
// zulu21.37.17 : 364
|
||||
// graalvm 21+35.1 : 403
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastjson2_features() {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.fastjson2_features(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2_features millis : " + millis);
|
||||
// zulu8.62.0.19 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.40.19 : 376
|
||||
// zulu8.62.0.19 : 703 746 710 706 700 682 717 698
|
||||
// zulu11.52.13 : 579 565 552 541 554 553 554 538
|
||||
// zulu17.40.19 : 600 604 597 593 578 567
|
||||
// oracle-jdk-17.0.6 : 593
|
||||
// oracle-jdk-17.0.6_vec : 593
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +31,7 @@ public class EishayParseUTF8BytesTest {
|
||||
System.out.println("dsljson millis : " + millis);
|
||||
// zulu8.62.0.19 : 658
|
||||
// zulu11.52.13 : 818
|
||||
// zulu17.32.13 : 854 1050
|
||||
// zulu17.32.13 : 854
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,14 +45,13 @@ public class EishayParseUTF8BytesTest {
|
||||
System.out.println("jackson millis : " + millis);
|
||||
// zulu8.62.0.19 : 963
|
||||
// zulu11.52.13 : 1058
|
||||
// zulu17.32.13 : 1064 1175
|
||||
// zulu17.32.13 : 1064
|
||||
// graalvm_17.0.7 600
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
fastjson2();
|
||||
// fastjson2_features();
|
||||
// dsljson();
|
||||
// jackson();
|
||||
}
|
||||
|
@ -32,25 +32,9 @@ public class EishayWriteBinaryArrayMappingTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayWriteBinaryArrayMapping-jsonb millis : " + millis);
|
||||
// zulu8.62.0.19 : 796
|
||||
// zulu11.52.13 : 782
|
||||
// zulu17.32.13 : 790 767 716 804
|
||||
}
|
||||
}
|
||||
|
||||
public static void fury() throws Exception {
|
||||
System.out.println("fury size " + benchmark.furySize()); // 388
|
||||
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
benchmark.fury(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("EishayWriteBinaryArrayMapping-fury millis : " + millis);
|
||||
// zulu8.62.0.19 : 1551
|
||||
// zulu11.52.13 : 1126
|
||||
// zulu17.32.13 : 1058
|
||||
// zulu8.62.0.19 : 1265
|
||||
// zulu11.52.13 : 749
|
||||
// zulu17.32.13 : 804 766
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +56,6 @@ public class EishayWriteBinaryArrayMappingTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
jsonb();
|
||||
// fury();
|
||||
// kryo();
|
||||
// protobuf();
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ public class EishayWriteStringTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.70.0.23 : 3001 2795 2550
|
||||
// zulu11.62.17 : 3288 2549 2338
|
||||
// zulu17.32.13 : 3305 2909 2503 2353 2356
|
||||
// zulu8.70.0.23 : 3001 2873
|
||||
// zulu11.62.17 : 3288 2974 3028
|
||||
// zulu17.32.13 : 3305 2909
|
||||
// zulu17.40.91_vec : 2527 2536
|
||||
}
|
||||
}
|
||||
@ -49,28 +49,28 @@ public class EishayWriteStringTest {
|
||||
System.out.println("jackson millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.32.13 : 5896
|
||||
// zulu17.32.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void wastjson() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.wastjson(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("wastjson millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu17.32.13 :
|
||||
// zulu11.52.13 : 5246
|
||||
// zulu8.58.0.13 : 467
|
||||
// zulu17.32.13 : 542
|
||||
// zulu11.52.13 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void gson() throws Exception {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < LOOP; ++i) {
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
benchmark.gson(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
|
@ -14,30 +14,14 @@ public class EishayWriteUTF8BytesTest {
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2 millis : " + millis);
|
||||
// zulu8.58.0.13 : 2527
|
||||
// zulu11.52.13 : 337 314 289 2888 2606 2441 2026
|
||||
// zulu17.40.19 : 317 320 285 2446 2069
|
||||
// zulu8.58.0.13 : 336 347 317
|
||||
// zulu11.52.13 : 337 314 289 2888 2606 2441 2413 2401 2397
|
||||
// zulu17.40.19 : 317 320 285
|
||||
// zulu17.40.19_vec : 267 250
|
||||
// graalvm_17.0.7 207
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastjson2_features() {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 10_000_000; ++i) {
|
||||
benchmark.fastjson2_features(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("fastjson2_features millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.40.19 : 2393
|
||||
// zulu17.40.19_vec :
|
||||
// graalvm_17.0.7
|
||||
}
|
||||
}
|
||||
|
||||
public static void jackson() throws Exception {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
@ -68,7 +52,6 @@ public class EishayWriteUTF8BytesTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
fastjson2();
|
||||
// fastjson2_features();
|
||||
// gson();
|
||||
// jackson();
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import com.alibaba.fastjson2.util.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BigDecimalToPlainStringTest {
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
|
||||
public static String toString(long unscaledVal, int scale) {
|
||||
if (scale == 0) {
|
||||
return Long.toString(unscaledVal);
|
||||
}
|
||||
|
||||
boolean negative = false;
|
||||
if (unscaledVal < 0) {
|
||||
unscaledVal = -unscaledVal;
|
||||
negative = true;
|
||||
}
|
||||
|
||||
int size = IOUtils.stringSize(unscaledVal);
|
||||
int insertionPoint = size - scale;
|
||||
|
||||
byte[] buf;
|
||||
if (insertionPoint == 0) {
|
||||
buf = new byte[size + 2];
|
||||
} else if (insertionPoint < 0) {
|
||||
buf = new byte[size + 2 - insertionPoint];
|
||||
} else {
|
||||
long power = POWER_TEN[scale - 1];
|
||||
long div = unscaledVal / power;
|
||||
long rem = unscaledVal - div * power;
|
||||
buf = new byte[IOUtils.stringSize(div) + 1 + scale];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static final long[] POWER_TEN = {
|
||||
10,
|
||||
100,
|
||||
1000,
|
||||
10000,
|
||||
100000,
|
||||
1000000,
|
||||
10000000,
|
||||
100000000,
|
||||
1000000000,
|
||||
10000000000L,
|
||||
100000000000L,
|
||||
1000000000000L,
|
||||
10000000000000L,
|
||||
100000000000000L,
|
||||
1000000000000000L,
|
||||
10000000000000000L,
|
||||
100000000000000000L,
|
||||
1000000000000000000L,
|
||||
};
|
||||
}
|
@ -30,7 +30,7 @@ public class DateFormat19Test {
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DateFormat19-formatYMDHMS19 millis : " + millis);
|
||||
// zulu8.58.0.13 : 3161 3589
|
||||
// zulu11.52.13 : 3410 3623 1589 1559
|
||||
// zulu11.52.13 : 3410
|
||||
// zulu17.38.21 :
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,7 @@ public class DateFormat19Test {
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DateFormat19-fastjsonFormat2 millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 : 3501 2386 2078
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 :
|
||||
}
|
||||
}
|
||||
@ -81,8 +81,8 @@ public class DateFormat19Test {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// fastjsonFormat();
|
||||
// formatYMDHMS19();
|
||||
fastjsonFormat2();
|
||||
// fastjsonFormat2();
|
||||
// javaTimeDateFormatter();
|
||||
// simpleParseX();
|
||||
simpleParseX();
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
public class DateToStringTest {
|
||||
static final Blackhole BH = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.");
|
||||
static final DateToString benchmark = new DateToString();
|
||||
static final int COUNT = 100_000_000;
|
||||
|
||||
public static void dateToString() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.dateToString(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DateToString-dateToString millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 :
|
||||
// jdk22-ea : 2495
|
||||
// jdk22-baseline : 5669
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
dateToString();
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
public class DecimalDToStringTest {
|
||||
static final Blackhole BH = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.");
|
||||
static final DecimalDToString benchmark = new DecimalDToString();
|
||||
static final int COUNT = 10_000_000;
|
||||
|
||||
public static void toPlainString() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toPlainString(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toPlainStringDec millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void toPlainStringDec() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toPlainStringDec(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toPlainStringDec millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void layoutChars() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.layoutChars(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-layoutChars millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// jdk22-ea : 3321 2775 2449
|
||||
// jdk22-base : 3703
|
||||
}
|
||||
}
|
||||
|
||||
public static void toStringCharWithInt8() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toStringCharWithInt8(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toStringCharWithInt8 millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 :
|
||||
// openjdk20 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void toStringCharWithInt8UTF16() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toStringCharWithInt8UTF16(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toStringCharWithInt8UTF16 millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// jdk21.0.0 :
|
||||
// openjdk22 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// Random r = new Random();
|
||||
// int value = Math.abs(r.nextInt());
|
||||
// BigDecimal h = new BigDecimal("" + ((long) value + (long) Integer.MAX_VALUE)
|
||||
// + ((long) value + (long) Integer.MAX_VALUE) + ".55");
|
||||
// BigDecimal l = new BigDecimal("" + ((long) value + (long) Integer.MAX_VALUE) + ".55");
|
||||
// BigDecimal s = new BigDecimal("" + ((long) value / 1000) + ".55");
|
||||
|
||||
// toPlainString();
|
||||
// toPlainStringDec();
|
||||
layoutChars();
|
||||
// toStringCharWithInt8();
|
||||
// toStringCharWithInt8UTF16();
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package com.alibaba.fastjson2.benchmark.fastcode;
|
||||
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Random;
|
||||
|
||||
public class DecimalHugeToStringTest {
|
||||
static final Blackhole BH = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.");
|
||||
static final DecimalHugToString benchmark = new DecimalHugToString();
|
||||
static final int COUNT = 10_000_000;
|
||||
|
||||
public static void toPlainString() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toPlainString(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toPlainStringDec millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void toPlainStringDec() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toPlainStringDec(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toPlainStringDec millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 : 2122 1931 1645 1553
|
||||
}
|
||||
}
|
||||
|
||||
public static void layoutChars() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.layoutChars(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-layoutChars millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// jdk22-ea : 1352
|
||||
// jdk22-base : 2658
|
||||
}
|
||||
}
|
||||
|
||||
public static void toStringCharWithInt8() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toStringCharWithInt8(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toStringCharWithInt8 millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// zulu17.38.21 :
|
||||
// openjdk20 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void toStringCharWithInt8UTF16() throws Throwable {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
benchmark.toStringCharWithInt8UTF16(BH);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - start;
|
||||
System.out.println("DecimalToString-toStringCharWithInt8UTF16 millis : " + millis);
|
||||
// zulu8.58.0.13 :
|
||||
// zulu11.52.13 :
|
||||
// jdk21.0.0 :
|
||||
// openjdk22 :
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
Random r = new Random();
|
||||
// int value = Math.abs(r.nextInt());
|
||||
// BigDecimal h = new BigDecimal("" + ((long) value + (long) Integer.MAX_VALUE)
|
||||
// + ((long) value + (long) Integer.MAX_VALUE) + ".55");
|
||||
// BigDecimal l = new BigDecimal("" + ((long) value + (long) Integer.MAX_VALUE) + ".55");
|
||||
|
||||
// toPlainString();
|
||||
// toPlainStringDec();
|
||||
BigDecimal d = new BigDecimal(r.nextDouble());
|
||||
layoutChars();
|
||||
// toStringCharWithInt8();
|
||||
// toStringCharWithInt8UTF16();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user