PageRenderTime 6887ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/performance/org/nutz/json/JsonFaster.java

http://nutz.googlecode.com/
Java | 59 lines | 47 code | 11 blank | 1 comment | 2 complexity | 21fbcb20adfc8389d52cbc184c008d17 MD5 | raw file
Possible License(s): Apache-2.0
  1. package org.nutz.json;
  2. import org.junit.Test;
  3. import org.nutz.json.bean.JsonObject;
  4. import org.nutz.lang.Stopwatch;
  5. import com.alibaba.fastjson.JSON;
  6. public class JsonFaster {
  7. @Test
  8. public void json() {
  9. nutzJson(10000);
  10. fastJson(10000);
  11. Stopwatch sw = Stopwatch.begin();
  12. nutzJson(50*10000);
  13. sw.stop();
  14. System.out.println("Nutz-Json 50w???: " + sw.getDuration());
  15. sw.start();
  16. fastJson(50*10000);
  17. System.out.println("Fast-Json 50w???: " + sw.getDuration());
  18. //-------------------------------------------------------------------
  19. sw.start();
  20. nutzJson(50*10000);
  21. sw.stop();
  22. System.out.println("Nutz-Json 50w???: " + sw.getDuration());
  23. sw.start();
  24. fastJson(50*10000);
  25. sw.stop();
  26. System.out.println("Fast-Json 50w???: " + sw.getDuration());
  27. }
  28. public void nutzJson(int time) {
  29. JsonObject obj = new JsonObject();
  30. obj.setName("wendal");
  31. for (int i = 0; i < time; i++) {
  32. String jsonStr = Json.toJson(obj);
  33. obj = Json.fromJson(JsonObject.class, jsonStr);
  34. }
  35. }
  36. public void fastJson(int time) {
  37. JsonObject obj = new JsonObject();
  38. obj.setName("wendal");
  39. for (int i = 0; i < time; i++) {
  40. String jsonStr = JSON.toJSONString(obj);
  41. obj = JSON.parseObject(jsonStr, JsonObject.class);
  42. }
  43. }
  44. public static void main(String[] args) throws Throwable {
  45. Thread.sleep(60*1000);
  46. new JsonFaster().json();
  47. }
  48. }