mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -19,6 +19,7 @@ package org.dromara.hutool.jmh.json;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.gson.JsonElement;
|
||||
import org.dromara.hutool.json.JSON;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import org.dromara.hutool.json.engine.JSONEngine;
|
||||
import org.dromara.hutool.json.engine.JSONEngineFactory;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
@@ -43,7 +44,7 @@ public class FromJsonStringStrJmh {
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
jsonStr = "{\"name\":\"张三\",\"age\":18,\"birthday\":\"2020-01-01\"}";
|
||||
jsonStr = JSONJmhData.jsonStr;
|
||||
|
||||
jacksonEngine = JSONEngineFactory.createEngine("jackson");
|
||||
gsonEngine = JSONEngineFactory.createEngine("gson");
|
||||
@@ -70,4 +71,9 @@ public class FromJsonStringStrJmh {
|
||||
public void hutoolJSONJmh() {
|
||||
hutoolEngine.fromJsonString(jsonStr, JSON.class);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void hutoolJSONParseJmh() {
|
||||
JSONUtil.parseObj(jsonStr);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,43 @@
|
||||
package org.dromara.hutool.jmh.json;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class JSONJmhData {
|
||||
public static String jsonStr = "{\n" +
|
||||
" \"name\": \"张三\",\n" +
|
||||
" \"age\": 18,\n" +
|
||||
" \"birthday\": \"2020-01-01\",\n" +
|
||||
" \"booleanValue\": true,\n" +
|
||||
" \"jsonObjectSub\": {\n" +
|
||||
" \"subStr\": \"abc\",\n" +
|
||||
" \"subNumber\": 150343445454,\n" +
|
||||
" \"subBoolean\": true\n" +
|
||||
" },\n" +
|
||||
" \"jsonArraySub\": [\n" +
|
||||
" \"abc\",\n" +
|
||||
" 123,\n" +
|
||||
" false\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
|
||||
@Data
|
||||
public static class TestBean{
|
||||
private String name;
|
||||
private int age;
|
||||
private boolean gender;
|
||||
private Date createDate;
|
||||
private Object nullObj;
|
||||
private SubBean jsonObjectSub;
|
||||
private List<Object> jsonArraySub;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SubBean{
|
||||
private String subStr;
|
||||
private Long subNumber;
|
||||
private boolean subBoolean;
|
||||
}
|
||||
}
|
@@ -29,6 +29,7 @@ public class JsonAddJmh {
|
||||
private JsonArray gson;
|
||||
private com.alibaba.fastjson2.JSONArray fastJSON;
|
||||
private ArrayNode jackson;
|
||||
private ArrayList<Object> arrayList;
|
||||
|
||||
|
||||
@Setup
|
||||
@@ -43,6 +44,7 @@ public class JsonAddJmh {
|
||||
gson = new JsonArray();
|
||||
fastJSON = new com.alibaba.fastjson2.JSONArray();
|
||||
jackson = JsonNodeFactory.instance.arrayNode();
|
||||
arrayList = new ArrayList<>();
|
||||
Console.log("数据完毕");
|
||||
}
|
||||
|
||||
@@ -67,4 +69,9 @@ public class JsonAddJmh {
|
||||
public void jacksonJmh(){
|
||||
testData.forEach(jackson::add);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void arrayListJmh(){
|
||||
testData.forEach(arrayList::add);
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ public class JsonPutJmh {
|
||||
private JsonObject gson;
|
||||
private com.alibaba.fastjson2.JSONObject fastJSON;
|
||||
private ObjectNode jackson;
|
||||
private HashMap<String, Object> hashMap;
|
||||
|
||||
|
||||
@Setup
|
||||
@@ -41,6 +42,7 @@ public class JsonPutJmh {
|
||||
gson = new JsonObject();
|
||||
fastJSON = new com.alibaba.fastjson2.JSONObject();
|
||||
jackson = JsonNodeFactory.instance.objectNode();
|
||||
hashMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@@ -63,4 +65,9 @@ public class JsonPutJmh {
|
||||
public void jacksonJmh(){
|
||||
testData.forEach(jackson::put);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void hashMapJmh(){
|
||||
testData.forEach(hashMap::put);
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ public class ParseTreeJmh {
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
jsonStr = "{\"name\":\"张三\",\"age\":18,\"birthday\":\"2020-01-01\"}";
|
||||
jsonStr = JSONJmhData.jsonStr;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
|
Reference in New Issue
Block a user