z901_perf_tst.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2017 gnosygnu@gmail.com
  4. XOWA is licensed under the terms of the General Public License (GPL) Version 3,
  5. or alternatively under the terms of the Apache License Version 2.0.
  6. You may use XOWA according to either of these licenses as is most appropriate
  7. for your project on a case-by-case basis.
  8. The terms of each license can be found in the source code repository:
  9. GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
  10. Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
  11. */
  12. package gplx.gfml; import gplx.*;
  13. import org.junit.*; import gplx.core.strings.*; import gplx.core.envs.*;
  14. public class z901_perf_tst {
  15. TimerWatch tmr = TimerWatch.new_();
  16. @Test public void EmptyTestSoJunitWillNotFail() {}
  17. // @Test
  18. public void Long() {
  19. // String longText = String_.Repeat("a", 30 * 1000 * 1000);
  20. String longText = Io_mgr.Instance.LoadFilStr(Io_url_.new_any_("C:\\core_weekly.temp.gfio"));
  21. // String_bldr sbXml = String_bldr_.new_();
  22. // sbXml.Add("<");
  23. // sbXml.Add(longText);
  24. // sbXml.Add("/>");
  25. // tmr.Bgn();
  26. // gplx.langs.xmls.XmlDoc_.parse(sbXml.To_str());
  27. // tmr.End_and_print("xml"); // 400
  28. String_bldr sbGfml = String_bldr_.new_();
  29. for (int i = 0; i < 10; i++) {
  30. sbGfml.Add(longText);
  31. // sbGfml.Add(longText);
  32. // sbGfml.Add(longText);
  33. // sbGfml.Add(longText);
  34. }
  35. // tmr.Bgn();
  36. // gplx.core.texts.CharStream.pos0_(sbGfml.To_str());
  37. // tmr.End_and_print("char"); // 1700
  38. tmr.Bgn();
  39. GfmlDoc_.parse_any_eol_(sbGfml.To_str());
  40. tmr.End_and_print("gfml"); // 1700
  41. }
  42. //@Test
  43. public void Prop() {
  44. int max = 100 * 1000 * 1000;
  45. PerfFieldVsProc c = new PerfFieldVsProc();
  46. int v = 0;
  47. tmr.Bgn();
  48. for (int i = 0; i < max; i++)
  49. v = member;
  50. tmr.End_and_print("member");
  51. tmr.Bgn();
  52. for (int i = 0; i < max; i++)
  53. v = c.Val_field;
  54. tmr.End_and_print("field");
  55. tmr.Bgn();
  56. for (int i = 0; i < max; i++)
  57. v = c.Val_proc();
  58. tmr.End_and_print("proc");
  59. Tfds.Write(v);
  60. }
  61. // @Test
  62. // public void ClassComp() {
  63. // int max = 100 * 1000 * 1000;
  64. // ClassType ct = new ClassType3();
  65. // long v = 0;
  66. // // 2625 CS, 718 JAVA
  67. // tmr.Bgn();
  68. // for (int i = 0; i < max; i++) {
  69. // if (ct.Type() == ClassType_.Type_1) v += 1;
  70. // else if (ct.Type() == ClassType_.Type_2) v += 2;
  71. // else if (ct.Type() == ClassType_.Type_3) v += 3;
  72. // }
  73. // tmr.End_and_print("var");
  74. // v = 0;
  75. // // 12437 CS, 578 JAVA
  76. // tmr.Bgn();
  77. // for (int i = 0; i < max; i++) {
  78. // Class<?> type = ct.getClass();
  79. // if (type == typeof(ClassType1)) v += 1;
  80. // else if (type == typeof(ClassType2)) v += 2;
  81. // else if (type == typeof(ClassType3)) v += 3;
  82. // }
  83. // tmr.End_and_print("type");
  84. // }
  85. interface ClassType {int Type();}
  86. class ClassType_ {public static final int Type_1 = 1, Type_2 = 2, Type_3 = 3;}
  87. class ClassType1 implements ClassType {public int Type() {return ClassType_.Type_1;}}
  88. class ClassType2 implements ClassType {public int Type() {return ClassType_.Type_2;}}
  89. class ClassType3 implements ClassType {public int Type() {return ClassType_.Type_3;}}
  90. int member = 1;
  91. }
  92. class PerfFieldVsProc {
  93. public int Val_field = 1;
  94. public int Val_proc() {return 1;}
  95. }
  96. class TimerWatch {
  97. public void Bgn() {bgnTime = System_.Ticks();} long bgnTime;
  98. public void End() {duration = System_.Ticks() - bgnTime;} long duration;
  99. public void End_and_print(String text) {
  100. this.End();
  101. Tfds.Write(XtoStr_ms() + " " + text);
  102. }
  103. public String XtoStr_ms() {return Long_.To_str(duration);}
  104. public static TimerWatch new_() {
  105. TimerWatch rv = new TimerWatch();
  106. rv.Bgn();
  107. return rv;
  108. } TimerWatch() {}
  109. }