Skip to content

Commit 9078796

Browse files
committed
explore performance test limits
1 parent 129f27c commit 9078796

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

src/main/java/de/tilman_neumann/jml/quadraticResidues/QuadraticResiduesMod2PowN.java

+9
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public static List<BigInteger> getQuadraticResiduesMod2PowN_testAll_big(int n) {
142142
/**
143143
* Compute all quadratic residues modulus 2^n.
144144
*
145+
* OutOfMemoryError at n=29.
146+
*
145147
* @param n
146148
* @return list of quadratic residue modulus 2^n
147149
*/
@@ -159,6 +161,8 @@ public static List<Long> getQuadraticResiduesMod2PowN_testAll(int n) {
159161
/**
160162
* Compute all quadratic residues modulus 2^n.
161163
*
164+
* OutOfMemoryError at n=31.
165+
*
162166
* @param n
163167
* @return list of quadratic residue modulus 2^n
164168
*/
@@ -175,6 +179,9 @@ public static List<Long> getQuadraticResiduesMod2PowN_testAll_v2(int n) {
175179

176180
/**
177181
* Compute all quadratic residues modulus 2^n.
182+
*
183+
* OutOfMemoryError at n=30.
184+
*
178185
* @param n
179186
* @return list of quadratic residues
180187
*/
@@ -209,6 +216,8 @@ public static List<Long> getQuadraticResiduesMod2PowN(int n) {
209216
* Compute all quadratic residues modulus 2^n.
210217
* Fast implementation using a single array, not needing reallocations.
211218
*
219+
* OutOfMemoryError at n=33.
220+
*
212221
* @param n
213222
* @param array the array to fill with quadratic residues
214223
* @return number of quadratic residues modulus 2^n

src/test/java/de/tilman_neumann/jml/quadraticResidues/QuadraticResiduesMod2PowNPerformanceTest.java

+37-26
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,45 @@ public class QuadraticResiduesMod2PowNPerformanceTest {
4040
public static void main(String[] args) {
4141
ConfigUtil.initProject();
4242

43-
for (int n=0; ; n++) {
43+
for (int n=0; n<34; n++) {
4444
long t0, t1;
4545

46-
t0 = System.currentTimeMillis();
47-
List<BigInteger> quadraticResiduesMod2PowN_v0 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll_big(n);
48-
t1 = System.currentTimeMillis();
49-
LOG.info("v0: n = " + n + " has " + quadraticResiduesMod2PowN_v0.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v0 : "") + " -- duration = " + (t1-t0) + "ms");
50-
51-
t0 = System.currentTimeMillis();
52-
List<Long> quadraticResiduesMod2PowN_v1 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll(n);
53-
t1 = System.currentTimeMillis();
54-
LOG.info("v1: n = " + n + " has " + quadraticResiduesMod2PowN_v1.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v1 : "") + " -- duration = " + (t1-t0) + "ms");
55-
56-
t0 = System.currentTimeMillis();
57-
List<Long> quadraticResiduesMod2PowN_v2 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll_v2(n);
58-
t1 = System.currentTimeMillis();
59-
LOG.info("v2: n = " + n + " has " + quadraticResiduesMod2PowN_v2.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v2 : "") + " -- duration = " + (t1-t0) + "ms");
60-
61-
t0 = System.currentTimeMillis();
62-
List<Long> quadraticResiduesMod2PowN_v3 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN(n);
63-
t1 = System.currentTimeMillis();
64-
LOG.info("v3: n = " + n + " has " + quadraticResiduesMod2PowN_v3.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v3 : "") + " -- duration = " + (t1-t0) + "ms");
65-
66-
t0 = System.currentTimeMillis();
67-
long[] array = new long[((1<<n) / 6) + 6];
68-
int count = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN(n, array);
69-
t1 = System.currentTimeMillis();
70-
LOG.info("v4: n = " + n + " has " + count + " quadratic residues" + (SHOW_ELEMENTS ? ": " + Arrays.toString(array) : "") + " -- duration = " + (t1-t0) + "ms");
46+
if (n<25) { // otherwise too slow
47+
t0 = System.currentTimeMillis();
48+
List<BigInteger> quadraticResiduesMod2PowN_v0 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll_big(n);
49+
t1 = System.currentTimeMillis();
50+
LOG.info("v0: n = " + n + " has " + quadraticResiduesMod2PowN_v0.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v0 : "") + " -- duration = " + (t1-t0) + "ms");
51+
}
52+
53+
if (n<29) { // avoid OutOfMemoryError
54+
t0 = System.currentTimeMillis();
55+
List<Long> quadraticResiduesMod2PowN_v1 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll(n);
56+
t1 = System.currentTimeMillis();
57+
LOG.info("v1: n = " + n + " has " + quadraticResiduesMod2PowN_v1.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v1 : "") + " -- duration = " + (t1-t0) + "ms");
58+
}
59+
60+
if (n<31) { // avoid OutOfMemoryError
61+
t0 = System.currentTimeMillis();
62+
List<Long> quadraticResiduesMod2PowN_v2 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll_v2(n);
63+
t1 = System.currentTimeMillis();
64+
LOG.info("v2: n = " + n + " has " + quadraticResiduesMod2PowN_v2.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v2 : "") + " -- duration = " + (t1-t0) + "ms");
65+
}
66+
67+
if (n<30) { // avoid OutOfMemoryError
68+
t0 = System.currentTimeMillis();
69+
List<Long> quadraticResiduesMod2PowN_v3 = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN(n);
70+
t1 = System.currentTimeMillis();
71+
LOG.info("v3: n = " + n + " has " + quadraticResiduesMod2PowN_v3.size() + " quadratic residues" + (SHOW_ELEMENTS ? ": " + quadraticResiduesMod2PowN_v3 : "") + " -- duration = " + (t1-t0) + "ms");
72+
}
73+
74+
if (n<33) { // avoid OutOfMemoryError
75+
t0 = System.currentTimeMillis();
76+
int arraySize = (int) ((1L<<n) / 6) + 6; // long conversion gives us 2 more n without "NegativeArraySizeException"
77+
long[] array = new long[arraySize];
78+
int count = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN(n, array);
79+
t1 = System.currentTimeMillis();
80+
LOG.info("v4: n = " + n + " has " + count + " quadratic residues" + (SHOW_ELEMENTS ? ": " + Arrays.toString(array) : "") + " -- duration = " + (t1-t0) + "ms");
81+
}
7182
}
7283
}
7384
}

0 commit comments

Comments
 (0)