Commits

Stepan Koltsov  committed 5f2f0ae

better

  • Participants
  • Parent commits 1c390a6

Comments (0)

Files changed (1)

File src/java/org/jetbrains/jet/perf/invokevirtual/InvokeVirtualTest.java

         EMPTY_LIST,
         ARRAY_LIST,
         ARL_CACHED,
+        UNMODIFIAB,
     }
 
     private int minCount() {
         System.out.println("iteration " + iteration + (record ? "" : " not recording"));
         int seed = random.nextInt();
         while (minCount() < 3) {
-            Kind what = Kind.values()[random.nextInt(3)];
+            Kind what = Kind.values()[random.nextInt(Kind.values().length)];
             long start = System.currentTimeMillis();
             int sum;
             switch (what) {
                 case ARL_CACHED:
                     sum = runArrayListCached(seed);
                     break;
+                case UNMODIFIAB:
+                    sum = runArrayListUnmodifiable(seed);
+                    break;
                 default:
                     throw new AssertionError();
             }
         return sum;
     }
 
+    private int runArrayListUnmodifiable(int seed) {
+        int sum = 0;
+        for (int i = 0; i < count; ++i) {
+            List<Integer> list = intsArrayListUnmodifiable(TestUtils.hash(i, seed));
+            for (Integer item : list) {
+                sum += item;
+            }
+        }
+        return sum;
+    }
+
     private int runEmptyList(int seed) {
         int sum = 0;
         for (int i = 0; i < count; ++i) {
         return list;
     }
 
+    private static final List<?> unmodifiableEmptyArrayList = Collections.unmodifiableList(emptyArrayList);
+
+    private List<Integer> intsArrayListUnmodifiable(int seed) {
+        int length = TestUtils.randomInRange(3, seed);
+        if (length == 0) {
+            return (List<Integer>) unmodifiableEmptyArrayList;
+        }
+        List<Integer> list = new ArrayList<Integer>(length);
+        for (int i = 0; i < length; ++i) {
+            list.add(randomInteger(TestUtils.hash(i, seed)));
+        }
+        return Collections.unmodifiableList(list);
+    }
+
 }