}
return r;
}
static void squareBenchmarks() {
final Timer t = new Timer(false);
t.tick("squareBenchmarks(), MAX_SQRT=" + Modular.MAX_SQRT_LONG);
final long[][][] rn = generateRN(1000, 1000);
t.tick("generateRN");
for(int i = 0; i < rn.length; i++) {
final long n = rn[i][0][0];
for(int j = 1; j < rn[i].length; j++) {
final long r = rn[i][j][0];
final long answer = rn[i][j][1];
final long s = square_slow(r, n);
if (s != answer)
assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s);
}
}
t.tick("square_slow");
for(int i = 0; i < rn.length; i++) {
final long n = rn[i][0][0];
long r2p64 = (0x4000000000000000L % n) << 1;
if (r2p64 >= n) r2p64 -= n;
for(int j = 1; j < rn[i].length; j++) {
final long r = rn[i][j][0];
final long answer = rn[i][j][1];
final long s = square(r, n, r2p64);
if (s != answer)
assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s);
}
}
t.tick("square");
for(int i = 0; i < rn.length; i++) {
final long n = rn[i][0][0];
final BigInteger N = BigInteger.valueOf(n);
for(int j = 1; j < rn[i].length; j++) {
final long r = rn[i][j][0];
final long answer = rn[i][j][1];
final BigInteger R = BigInteger.valueOf(r);
final long s = R.multiply(R).mod(N).longValue();
if (s != answer)
assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s);
}
}
t.tick("R.multiply(R).mod(N)");
for(int i = 0; i < rn.length; i++) {
final long n = rn[i][0][0];
final BigInteger N = BigInteger.valueOf(n);
for(int j = 1; j < rn[i].length; j++) {
final long r = rn[i][j][0];
final long answer = rn[i][j][1];
final BigInteger R = BigInteger.valueOf(r);
final long s = R.modPow(TWO, N).longValue();
if (s != answer)
assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s);
}
}
t.tick("R.modPow(TWO, N)");
}