@@ -32,11 +32,12 @@ public class NewVsOldNumberAppendTest {
32
32
static final String TMP = System .getProperty ("java.io.tmpdir" );
33
33
34
34
private static final int NUM_ENTRIES_PER_RECORD = 20 ;
35
- private static final int NUM_RECORDS = 400 * 1000 ;
35
+ private static final int NUM_RECORDS = 200 * 1000 ;
36
36
private static final int NUM_WARMUP_RECORDS = 40 * 1000 ;
37
37
private static final int TOTAL_RECORDS = NUM_RECORDS + NUM_WARMUP_RECORDS ;
38
38
private static final long [][] RANDOM_LONGS = new long [TOTAL_RECORDS ][NUM_ENTRIES_PER_RECORD ];
39
39
private static final double [][] RANDOM_DOUBLES = new double [TOTAL_RECORDS ][NUM_ENTRIES_PER_RECORD ];
40
+ private static final int MAX_PRECISION = 8 ;
40
41
41
42
private static final Random random = new Random ();
42
43
@@ -49,21 +50,15 @@ public void fillRandoms() {
49
50
for (int i = 0 ; i < TOTAL_RECORDS ; i ++) {
50
51
for (int j = 0 ; j < NUM_ENTRIES_PER_RECORD ; j ++) {
51
52
RANDOM_LONGS [i ][j ] = random .nextLong ();
52
- RANDOM_DOUBLES [i ][j ] = random .nextDouble ();
53
+ RANDOM_DOUBLES [i ][j ] = Math .max (123456.789 ,
54
+ random .nextDouble () % (10 * 1000 * 1000 ));
53
55
}
54
56
}
55
57
}
56
58
57
- @ Test
58
- public void testNumberAppends () throws IOException {
59
- System .gc ();
60
- timeAppends (Generation .NEW , ExcerptType .BYTE_BUFFER );
61
- System .gc ();
62
- timeAppends (Generation .NEW , ExcerptType .UNSAFE );
63
- System .gc ();
64
- timeAppends (Generation .OLD , ExcerptType .BYTE_BUFFER );
65
- System .gc ();
66
- timeAppends (Generation .OLD , ExcerptType .UNSAFE );
59
+ private enum NumberType {
60
+ LONG ,
61
+ DOUBLE
67
62
}
68
63
69
64
private enum Generation {
@@ -94,7 +89,23 @@ private String getStringRep() {
94
89
}
95
90
}
96
91
97
- private void timeAppends (Generation gen , ExcerptType excerptType ) throws IOException {
92
+ @ Test
93
+ public void testNumberAppends () throws IOException {
94
+ for (NumberType type : NumberType .values ()) {
95
+ System .gc ();
96
+ timeAppends (Generation .NEW , ExcerptType .BYTE_BUFFER , type );
97
+ System .gc ();
98
+ timeAppends (Generation .NEW , ExcerptType .UNSAFE , type );
99
+ System .gc ();
100
+ timeAppends (Generation .OLD , ExcerptType .BYTE_BUFFER , type );
101
+ System .gc ();
102
+ timeAppends (Generation .OLD , ExcerptType .UNSAFE , type );
103
+ }
104
+ }
105
+
106
+ private void timeAppends (Generation gen ,
107
+ ExcerptType excerptType ,
108
+ NumberType numType ) throws IOException {
98
109
String basePath = TMP + File .separator ;
99
110
100
111
String newPath = basePath + gen .getStringRep () + excerptType .getStringRep () + "Ic" ;
@@ -121,38 +132,20 @@ private void timeAppends(Generation gen, ExcerptType excerptType) throws IOExcep
121
132
122
133
excerpt .startExcerpt (2 * 10 * NUM_ENTRIES_PER_RECORD );
123
134
for (int j = 0 ; j < NUM_ENTRIES_PER_RECORD ; j ++) {
124
- excerpt .append (RANDOM_LONGS [i ][j ]);
125
- // excerpt.append(RANDOM_DOUBLES[i][j]);
135
+ if (numType == NumberType .LONG )
136
+ excerpt .append (RANDOM_LONGS [i ][j ]);
137
+ else if (numType == NumberType .DOUBLE )
138
+ excerpt .append (RANDOM_DOUBLES [i ][j ], (j % MAX_PRECISION + 2 ));
139
+ else
140
+ throw new AssertionError ();
126
141
}
127
142
excerpt .finish ();
128
143
}
129
144
newIc .close ();
130
145
131
146
long time = System .nanoTime () - start ;
132
- System .out .println (gen + " " + excerptType + " time taken " +
147
+ System .out .println (numType + " " + gen + " " + excerptType + " time taken " +
133
148
(time / 1000000 ) + " ms" );
134
-
135
- /*
136
- // Read out values to ensure they were correct and prevent possible DCE
137
- IndexedChronicle ic = new IndexedChronicle(newPath);
138
- ic.useUnsafe(excerptType == ExcerptType.UNSAFE);
139
- Excerpt readExcerpt = ic.createExcerpt();
140
- for (int i = 0; i < TOTAL_RECORDS; i++) {
141
- boolean found = readExcerpt.nextIndex();
142
- if (!found)
143
- assertTrue(found);
144
- for (int j = 0; j < NUM_ENTRIES_PER_RECORD; j++) {
145
- long l = readExcerpt.readLong();
146
- double d = readExcerpt.readDouble();
147
- if (l != RANDOM_LONGS[i][j])
148
- assertEquals(l, RANDOM_LONGS[i][j]);
149
- if (d != RANDOM_DOUBLES[i][j])
150
- assertEquals(d, RANDOM_DOUBLES[i][j]);
151
- }
152
- readExcerpt.finish();
153
- }
154
- ic.close();
155
- */
156
149
}
157
150
158
151
private static void deleteOnExit (String basePath ) {
0 commit comments