Weblogic & Tomcat simple java loop performance varies -


have issue performance of simple loop (see code below in looptest.performtest) varies dramatically, consistent lifetime of process.

for example, when run within weblogic/tomcat may achieve average of 3.5 billion iterations per second. re-start , may achieve 20 million iterations per second. remain consistent lifetime of process. when has been run directly command line, on every occasion, has run fast.

this has been run under linux, windows, tomcat & weblogic. slow execution occurs more regularly in weblogic tomcat.

test specifics

the test code moves potential os calls (timing) before , after test, differing size loops should allow slow os calls apparent progressive apparent performance improvement loop size increases.

the number of iterations performed test determined time (see runtest) rather being fixed due large variation in performance , more complex may expected.

public static abstract class performancetest {      private final string name;      public performancetest(string name) {         this.name = name;     }      /**      * return value ensure loops etc not optimised away.      *       * @param loopcount      * @return      */     public abstract long performtest(final long loopcount);      public string getname() {         return name;     } }  private static class looptest extends performancetest {     looptest() {         super("loop");     }      @override     public long performtest(final long loopcount) {         long sum=0;         for(long i=0;i<loopcount;i++) {             sum+=i;         }          return sum;     } }  public static list<performancetest> loadtests() {      list<performancetest> performancetests = new arraylist<performancetest>();      performancetests.add(new looptest());      return performancetests; }  public static void main(string[] argv) {     int maxduration = 30;      if (argv.length == 1) {         maxduration = integer.parseint(argv[0]);     }      list<performancetest> tests = loadtests();      for(performancetest test : tests) {         runtest(test, maxduration);     } }  public static void runtest(performancetest test, int maxduration) {     system.out.println("processing " + test.getname());      long stopduration = 1000 * maxduration;      long estimatedduration = 1;     long priordelta = 1;     long loopcount=10;      while (estimatedduration < stopduration) {         long starttime = system.currenttimemillis();          test.performtest(loopcount);          long endtime = system.currenttimemillis();          long delta = endtime - starttime;          estimatedduration = delta * math.max(10, delta / math.min(estimatedduration, priordelta));          if (estimatedduration <= 0) {             estimatedduration = 1;         }          priordelta = delta;          if (priordelta <= 0) {             priordelta = 1;         }          if (delta > 0) {             double itemspersecond = 1000 * (double)loopcount / (double)delta;              decimalformat formatter;             if (itemspersecond < 1) {                 formatter = new decimalformat( "#,###,###,##0.000");             } else if (itemspersecond < 10) {                 formatter = new decimalformat( "#,###,###,##0.0");             } else {                  formatter = new decimalformat( "#,###,###,##0");             }              system.out.println("    " + loopcount + " : duration " + delta + ", items per-second: " + formatter.format(itemspersecond));         }          loopcount*=10;     } } 


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -