24
24
@ SuppressWarnings ("WeakerAccess" )
25
25
public class MyBenchmark {
26
26
27
+ private static final Integer [] INTS =
28
+ new Integer [] { Integer .valueOf (0 ), Integer .valueOf (1 ), Integer .valueOf (2 ),
29
+ Integer .valueOf (3 ), Integer .valueOf (4 ), Integer .valueOf (5 ),
30
+ Integer .valueOf (6 ), Integer .valueOf (7 ), Integer .valueOf (8 ),
31
+ Integer .valueOf (9 ), Integer .valueOf (10 ), Integer .valueOf (11 ),
32
+ Integer .valueOf (12 ), Integer .valueOf (13 ), Integer .valueOf (14 ),
33
+ Integer .valueOf (15 ) };
34
+
27
35
static List <Integer > buildList2 (int maxIdx ) {
28
36
List <Integer > empty = new ArrayList <>();
29
37
for (int i = 0 ; i < maxIdx ; i ++) {
30
- empty .add (i );
38
+ empty .add (INTS [ i & 0xf ] );
31
39
}
32
40
return empty ;
33
41
}
34
42
35
43
static scala .collection .immutable .Vector <Integer > buildScala (int maxIdx ) {
36
44
scala .collection .immutable .Vector <Integer > empty = Vector$ .MODULE$ .empty ();
37
45
for (int i = 0 ; i < maxIdx ; i ++) {
38
- empty = empty .appendBack (i );
46
+ empty = empty .appendBack (INTS [ i & 0xf ] );
39
47
}
40
48
return empty ;
41
49
}
42
50
43
51
@ SuppressWarnings ("unchecked" )
44
52
static <T extends BaseList <Integer >> T buildList (T empty , int maxIdx ) {
45
53
for (int i = 0 ; i < maxIdx ; i ++) {
46
- empty = (T ) empty .append (i );
54
+ empty = (T ) empty .append (INTS [ i & 0xf ] );
47
55
}
48
56
return empty ;
49
57
}
50
58
51
59
static ImRrbt <Integer > insertAtZeroRrb (int maxIdx ) {
52
60
ImRrbt <Integer > empty = empty ();
53
61
for (int i = maxIdx ; i >= 0 ; i --) {
54
- empty = empty .insert (0 , i );
62
+ empty = empty .insert (0 , INTS [ i & 0xf ] );
55
63
}
56
64
return empty ;
57
65
}
58
66
59
67
public static MutableRrbt <Integer > insertAtZeroRrbMut (int maxIdx ) {
60
68
MutableRrbt <Integer > empty = RrbTree .emptyMutable ();
61
69
for (int i = maxIdx ; i >= 0 ; i --) {
62
- empty = empty .insert (0 , i );
70
+ empty = empty .insert (0 , INTS [ i & 0xf ] );
63
71
}
64
72
return empty ;
65
73
}
66
74
67
75
public static List <Integer > insertAtZeroList (int maxIdx ) {
68
76
ArrayList <Integer > empty = new ArrayList <>();
69
77
for (int i = maxIdx ; i >= 0 ; i --) {
70
- empty .add (0 , i );
78
+ empty .add (0 , INTS [ i & 0xf ] );
71
79
}
72
80
return empty ;
73
81
}
74
82
75
83
public static scala .collection .immutable .Vector <Integer > insertAtZeroScala (int maxIdx ) {
76
84
scala .collection .immutable .Vector <Integer > empty = Vector$ .MODULE$ .empty ();
77
85
for (int i = maxIdx ; i >= 0 ; i --) {
78
- empty = empty .appendFront (i );
86
+ empty = empty .appendFront (INTS [ i & 0xf ] );
79
87
}
80
88
return empty ;
81
89
}
82
90
83
91
public static RrbTree <Integer > randomInsertRrb (RrbTree empty , int maxIdx ) {
84
92
Random rnd = new Random ();
85
93
for (int i = 0 ; i < maxIdx ; i ++) {
86
- empty = empty .insert (i > 1 ? rnd .nextInt (i ) : 0 , i );
94
+ empty = empty .insert (i > 1 ? rnd .nextInt (i ) : 0 , INTS [ i & 0xf ] );
87
95
}
88
96
return empty ;
89
97
}
@@ -92,7 +100,7 @@ public static List<Integer> randomInsertList(int maxIdx) {
92
100
Random rnd = new Random ();
93
101
List <Integer > empty = new ArrayList <>();
94
102
for (int i = 0 ; i < maxIdx ; i ++) {
95
- empty .add (i > 1 ? rnd .nextInt (i ) : 0 , i );
103
+ empty .add (i > 1 ? rnd .nextInt (i ) : 0 , INTS [ i & 0xf ] );
96
104
}
97
105
return empty ;
98
106
}
@@ -272,7 +280,7 @@ static Integer getEachScala(scala.collection.immutable.Vector<Integer> is) {
272
280
@ Benchmark public void BuildList100000 () { buildList2 (100000 ); }
273
281
@ Benchmark public void BuildList1000000 () { buildList2 (1000000 ); }
274
282
@ Benchmark public void BuildList10000000 () { buildList2 (10000000 ); }
275
- @ Benchmark public void BuildList100000000 () { buildList2 (100000000 ); }
283
+ // TOO Long: @Benchmark public void BuildList100000000() { buildList2(100000000); }
276
284
277
285
@ Benchmark public void BuildRrb1 () { buildList (empty (), 1 ); }
278
286
@ Benchmark public void BuildRrb10 () { buildList (empty (), 10 ); }
0 commit comments