DateWriteCase.java
package com.alibaba.fastjson2.benchmark.wast;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
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.concurrent.TimeUnit;
public class DateWriteCase {
static DateBean2 object = new DateBean2();
static ObjectMapper mapper = new ObjectMapper();
@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)
);
}
public static void main(String[] args) throws RunnerException {
Options options = new OptionsBuilder()
.include(DateWriteCase.class.getName())
.mode(Mode.Throughput)
.timeUnit(TimeUnit.MILLISECONDS)
.warmupIterations(3)
.forks(1)
.build();
new Runner(options).run();
}
}