lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yonik Seeley" <yo...@apache.org>
Subject Re: [jira] Created: (LUCENE-1257) Port to Java5
Date Wed, 09 Apr 2008 00:21:46 GMT
On Tue, Apr 8, 2008 at 7:48 PM, robert engels <rengels@ix.netcom.com> wrote:
> That is opposite of my testing:...
>
>  The 'foreach' is consistently faster.

It's consistently slower for me (I tested java5 and java6 both with
-server on a P4).
I'm a big fan of testing different methods in different test runs
(because of hotspot, gc, etc).

Example results:
$ c:/opt/jdk16/bin/java -server t 100000000 10 foreach
N = 10
method=foreachlen=1000000000 indexed time = 8734

Yonik@spidey /cygdrive/h/tmp
$ c:/opt/jdk16/bin/java -server t 100000000 10 iter
N = 10
method=iterlen=1000000000 indexed time = 7062


Here's my test code (a modified version of yours):

public class t {
   public static void main(String[] args) {
       int I = Integer.parseInt(args[0]); // 1000000
       int N = Integer.parseInt(args[1]); // 10
       String method = args[2].intern();  // foreach or iter

       String[] strings = new String[N];

       for (int i = 0; i < N; i++) {
           strings[i] = Integer.toString(i);
       }

       System.out.println("N = " + N);

       long len = 0;
       long start = System.currentTimeMillis();

       if (method=="foreach")
         for (int i = 0; i < I; i++) {
             for (String s : strings) {
                 len += s.length();
             }
         }
       else
         for (int i = 0; i < I; i++) {
             for (int j = 0; j < N; j++) {
                 len += strings[j].length();
             }
         }

           System.out.println("method="+method + "len="+len+" indexed
time = " + (System.currentTimeMillis() - start));
     }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message