No significant changes. Adding a few more tests to the primitives test case and...
[boo.git] / examples / arrayperformance.java
blobe0daec2d342cba07f5854504bdf31356dc9f8c66
1 //#region license
2 // boo - an extensible programming language for the CLI
3 // Copyright (C) 2004 Rodrigo Barreto de Oliveira
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //
19 // Contact Information
21 // mailto:rbo@acm.org
22 //#endregion
24 import java.util.ArrayList;
25 import java.util.Iterator;
27 class xrange implements Iterator
29 int _max;
30 int _current;
32 public xrange(int max)
34 _max = max;
35 _current = 0;
38 public boolean hasNext()
40 return _current < _max;
43 public Object next()
45 return new Integer(_current++);
48 public void remove()
53 public class arrayperformance
55 public static final int items = 2000000;
57 public static void main(String[] args)
59 test();
60 test();
61 test();
64 private static void test()
66 Object[] array = new Object[items];
67 for (int i = 0; i < array.length; i++)
69 array[i] = new Object();
72 ArrayList collect = new ArrayList();
74 Iterator i = new xrange(items);
75 long start = System.currentTimeMillis();
76 while (i.hasNext())
78 int index = ((Integer)i.next()).intValue();
79 collect.add(array[index]);
81 System.out.println((System.currentTimeMillis() - start) + " elapsed.");