-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* isASCII * swar * isASCIIChar * codestyle * fix build error * fix build error * add IOUtilsBench * optimize isASCII * remove unused code * add benchmark * bug fix
- Loading branch information
Showing
10 changed files
with
231 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
benchmark/src/main/java/com/alibaba/fastjson2/benchmark/wast/IOUtilsBench.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.