@@ -40,34 +40,45 @@ public class QuadraticResiduesMod2PowNPerformanceTest {
40
40
public static void main (String [] args ) {
41
41
ConfigUtil .initProject ();
42
42
43
- for (int n =0 ; ; n ++) {
43
+ for (int n =0 ; n < 34 ; n ++) {
44
44
long t0 , t1 ;
45
45
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
+ }
71
82
}
72
83
}
73
84
}
0 commit comments