You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2003/03/03 16:18:34 UTC

cvs commit: xml-xerces/java/samples/xni Counter.java

neilg       2003/03/03 07:18:34

  Modified:    java/samples/xni Counter.java
  Log:
  when memory usage is enabled in this sample, the garbage collector should be explicitly run before the parse so that the statistics reflect the amount of memory the parse actually used, rather than that plus whatever was used by initial class loading etc.  The current code actually returns negative values for certain platforms; thanks to Steve Dulin for pointing this out.
  
  Revision  Changes    Path
  1.13      +12 -6     xml-xerces/java/samples/xni/Counter.java
  
  Index: Counter.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/samples/xni/Counter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Counter.java	13 Feb 2003 23:41:52 -0000	1.12
  +++ Counter.java	3 Mar 2003 15:18:34 -0000	1.13
  @@ -547,16 +547,22 @@
               // parse file
               try {
                   long timeBefore = System.currentTimeMillis();
  -                long memoryBefore = Runtime.getRuntime().freeMemory();
  +                long memoryBefore = 0; 
  +                if(memoryUsage) {
  +                    System.gc();
  +                    memoryBefore = Runtime.getRuntime().freeMemory();
  +                }
                   for (int j = 0; j < repetition; j++) {
                       parser.parse(new XMLInputSource(null, arg, null));
                   }
  -                long memoryAfter = Runtime.getRuntime().freeMemory();
  -                long timeAfter = System.currentTimeMillis();
  +                long memory = Long.MIN_VALUE;
  +                if(memoryUsage) {
  +                    long memoryAfter = Runtime.getRuntime().freeMemory();
  +                    memory = memoryBefore - memoryAfter;
  +                }
   
  +                long timeAfter = System.currentTimeMillis();
                   long time = timeAfter - timeBefore;
  -                long memory = memoryUsage
  -                            ? memoryBefore - memoryAfter : Long.MIN_VALUE;
                   ((Counter)parser).printResults(out, arg, time,
                                                  memory, tagginess,
                                                  repetition);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org