fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static String stackTrace(Throwable cause) {
  11. if (cause == null)
  12. return "";
  13. StringWriter sw = new StringWriter(1024);
  14. final PrintWriter pw = new PrintWriter(sw);
  15. cause.printStackTrace(pw);
  16. pw.flush();
  17. return sw.toString();
  18. }
  19.  
  20. private static final String STATIC_TRACE = stackTrace (new RuntimeException("Daft"));
  21.  
  22. private static String stackString() {
  23. return (System.currentTimeMillis() + STATIC_TRACE);
  24. }
  25.  
  26. private static final long countReuse() {
  27. final long until = System.currentTimeMillis() + 500;
  28. long len = 0;
  29. long count = 0;
  30. RuntimeException except = new RuntimeException("Static");
  31. do {
  32. len += stackTrace(except).length();
  33. count++;
  34. } while (System.currentTimeMillis() < until);
  35. System.out.println("Reuse " + len);
  36. return count;
  37. }
  38.  
  39. private static final long countRecreate() {
  40. final long until = System.currentTimeMillis() + 500;
  41. long count = 0;
  42. long len = 0;
  43. do {
  44. len += stackTrace(new RuntimeException("Static")).length();
  45. count++;
  46. } while (System.currentTimeMillis() < until);
  47. System.out.println("Recreate " + len);
  48. return count;
  49. }
  50.  
  51. private static final long countFilled() {
  52. final long until = System.currentTimeMillis() + 500;
  53. long count = 0;
  54. long len = 0;
  55. do {
  56. len += stackTrace(new RuntimeException("Static").fillInStackTrace()).length();
  57. count++;
  58. } while (System.currentTimeMillis() < until);
  59. System.out.println("Filled " + len);
  60. return count;
  61. }
  62.  
  63. private static final long countString() {
  64. final long until = System.currentTimeMillis() + 500;
  65. long count = 0;
  66. long len = 0;
  67. do {
  68. len += stackString().length();
  69. count++;
  70. } while (System.currentTimeMillis() < until);
  71. System.out.println("Filled " + len);
  72. return count;
  73. }
  74.  
  75. public static void main (String[] args) throws java.lang.Exception
  76. {
  77. long a = countReuse();
  78. long b = countRecreate();
  79. long c = countFilled();
  80. long d = countString();
  81. long e = countReuse();
  82. long f = countRecreate();
  83. long g = countFilled();
  84. long h = countString();
  85. System.out.printf("Warm: Reuse %d Recreate %d Filled %d String %d%nReal: Reuse %d Recreate %d Filled %d String %d%n",
  86. a,b,c,d,e,f,g,h
  87. );
  88. }
  89. }
Success #stdin #stdout 4.07s 380352KB
stdin
Standard input is empty
stdout
Reuse 7379262
Recreate 4954872
Filled 4372230
Filled 40755680
Reuse 8737712
Recreate 5048680
Filled 4422822
Filled 41007680
Warm: Reuse 73062 Recreate 47643 Filled 42865 String 509446
Real: Reuse 86512 Recreate 48545 Filled 43361 String 512596