/src/test/java/com/alibaba/json/test/benchmark/basic/IntBenchmark.java

https://github.com/alibaba/fastjson · Java · 74 lines · 51 code · 10 blank · 13 comment · 4 complexity · 322f6d7012bdeba049c25d5b6d5a1441 MD5 · raw file

  1. package com.alibaba.json.test.benchmark.basic;
  2. import com.alibaba.fastjson.JSON;
  3. import java.util.Random;
  4. /**
  5. * Created by wenshao on 04/08/2017.
  6. */
  7. public class IntBenchmark {
  8. static String json = "{\"v1\":-1224609302,\"v2\":379420556,\"v3\":-1098099527,\"v4\":-2018662,\"v5\":422842162}";
  9. static String json2 = "{\"v1\":\"-1224609302\",\"v2\":\"379420556\",\"v3\":\"-1098099527\",\"v4\":\"-2018662\",\"v5\":\"422842162\"}";
  10. static String json3 = "{\n" +
  11. "\t\"v1\":\"-1224609302\",\n" +
  12. "\t\"v2\":\"379420556\",\n" +
  13. "\t\"v3\":\"-1098099527\",\n" +
  14. "\t\"v4\":\"-2018662\",\n" +
  15. "\t\"v5\":\"422842162\"\n" +
  16. "}";
  17. public static void main(String[] args) throws Exception {
  18. System.out.println(System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
  19. // Model model = new Model();
  20. // model.v1 = new Random().nextInt();
  21. // model.v2 = new Random().nextInt();
  22. // model.v3 = new Random().nextInt();
  23. // model.v4 = new Random().nextInt();
  24. // model.v5 = new Random().nextInt();
  25. //
  26. // System.out.println(JSON.toJSONString(model));
  27. for (int i = 0; i < 10; ++i) {
  28. perf(); // 1798
  29. // perf2(); // 1877
  30. // perf3(); // 20624 2334
  31. }
  32. }
  33. public static void perf() {
  34. long start = System.currentTimeMillis();
  35. for (int i = 0; i < 1000 * 1000 * 10; ++i) {
  36. JSON.parseObject(json, Model.class);
  37. }
  38. long millis = System.currentTimeMillis() - start;
  39. System.out.println("millis : " + millis);
  40. }
  41. public static void perf2() {
  42. long start = System.currentTimeMillis();
  43. for (int i = 0; i < 1000 * 1000 * 10; ++i) {
  44. JSON.parseObject(json2, Model.class);
  45. }
  46. long millis = System.currentTimeMillis() - start;
  47. System.out.println("millis : " + millis);
  48. }
  49. public static void perf3() {
  50. long start = System.currentTimeMillis();
  51. for (int i = 0; i < 1000 * 1000 * 10; ++i) {
  52. JSON.parseObject(json3, Model.class);
  53. }
  54. long millis = System.currentTimeMillis() - start;
  55. System.out.println("millis : " + millis);
  56. }
  57. public static class Model {
  58. public int v1;
  59. public int v2;
  60. public int v3;
  61. public int v4;
  62. public int v5;
  63. }
  64. }