測試裝備:
mac pro 6核12線程
測試代碼:
(1)序列化對象:
import lombok.Data;@Data
public class User {int id;String name;int age;String address;
}
(2)序列化邏輯:
import com.alibaba.fastjson.JSON;public class FastJsonTest {public static void main(String[] args) {User user = new User();long startTimestamp = System.currentTimeMillis();for (int i = 0; i < 1000; i++) {JSON.toJSONString(user);}long endTimestamp = System.currentTimeMillis();System.out.print("執行耗時:" + (endTimestamp - startTimestamp));}
}
測試結果:
執行次數 | 執行結果 |
10 | 執行耗時:80毫米 |
100 | 執行耗時:92毫秒 |
1000 | 執行耗時:100毫秒 |
10000 | 執行耗時:124毫米 |
? | ? |