Skip to content

Commit 51035a7

Browse files
author
Brian Burkhalter
committed
8294137: Review running times of java.math tests
Reviewed-by: darcy
1 parent 46cca1a commit 51035a7

File tree

3 files changed

+124
-79
lines changed

3 files changed

+124
-79
lines changed

test/jdk/java/math/BigInteger/BigIntegerTest.java

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1222,6 +1222,17 @@ public static void serialize() throws Exception {
12221222
*
12231223
*/
12241224
public static void main(String[] args) throws Exception {
1225+
// subset zero indicates to run all subsets
1226+
int subset = Integer.valueOf(System.getProperty("subset",
1227+
String.valueOf(1 + random.nextInt(3))));
1228+
if (subset < 0 || subset > 3) {
1229+
throw new RuntimeException("Unknown subset " + subset);
1230+
}
1231+
if (subset == 0)
1232+
System.out.println("Testing all subsets");
1233+
else
1234+
System.out.println("Testing subset " + subset);
1235+
12251236
// Some variables for sizing test numbers in bits
12261237
int order1 = ORDER_MEDIUM;
12271238
int order2 = ORDER_SMALL;
@@ -1237,52 +1248,57 @@ public static void main(String[] args) throws Exception {
12371248
if (args.length >3)
12381249
order4 = (int)((Integer.parseInt(args[3]))* 3.333);
12391250

1240-
constructor();
1241-
1242-
prime();
1243-
nextProbablePrime();
1251+
if (subset == 0 || subset == 1) {
1252+
constructor();
12441253

1245-
arithmetic(order1); // small numbers
1246-
arithmetic(order3); // Karatsuba range
1247-
arithmetic(order4); // Toom-Cook / Burnikel-Ziegler range
1254+
prime();
1255+
nextProbablePrime();
12481256

1249-
divideAndRemainder(order1); // small numbers
1250-
divideAndRemainder(order3); // Karatsuba range
1251-
divideAndRemainder(order4); // Toom-Cook / Burnikel-Ziegler range
1257+
arithmetic(order1); // small numbers
1258+
arithmetic(order3); // Karatsuba range
1259+
arithmetic(order4); // Toom-Cook / Burnikel-Ziegler range
12521260

1253-
pow(order1);
1254-
pow(order3);
1255-
pow(order4);
1261+
divideAndRemainder(order1); // small numbers
1262+
divideAndRemainder(order3); // Karatsuba range
1263+
divideAndRemainder(order4); // Toom-Cook / Burnikel-Ziegler range
12561264

1257-
square(ORDER_MEDIUM);
1258-
square(ORDER_KARATSUBA_SQUARE);
1259-
square(ORDER_TOOM_COOK_SQUARE);
1265+
pow(order1);
1266+
pow(order3);
1267+
pow(order4);
12601268

1261-
squareRoot();
1262-
squareRootAndRemainder();
1269+
square(ORDER_MEDIUM);
1270+
square(ORDER_KARATSUBA_SQUARE);
1271+
square(ORDER_TOOM_COOK_SQUARE);
12631272

1264-
bitCount();
1265-
bitLength();
1266-
bitOps(order1);
1267-
bitwise(order1);
1273+
squareRoot();
1274+
squareRootAndRemainder();
12681275

1269-
shift(order1);
1276+
bitCount();
1277+
bitLength();
1278+
bitOps(order1);
1279+
bitwise(order1);
12701280

1271-
byteArrayConv(order1);
1281+
shift(order1);
12721282

1273-
modInv(order1); // small numbers
1274-
modInv(order3); // Karatsuba range
1275-
modInv(order4); // Toom-Cook / Burnikel-Ziegler range
1283+
byteArrayConv(order1);
12761284

1277-
modExp(order1, order2);
1278-
modExp2(order1);
1285+
modInv(order1); // small numbers
1286+
modInv(order3); // Karatsuba range
1287+
}
1288+
if (subset == 0 || subset == 2) {
1289+
modInv(order4); // Toom-Cook / Burnikel-Ziegler range
12791290

1280-
stringConv();
1281-
serialize();
1291+
modExp(order1, order2);
1292+
modExp2(order1);
1293+
}
1294+
if (subset == 0 || subset == 3) {
1295+
stringConv();
1296+
serialize();
12821297

1283-
multiplyLarge();
1284-
squareLarge();
1285-
divideLarge();
1298+
multiplyLarge();
1299+
squareLarge();
1300+
divideLarge();
1301+
}
12861302

12871303
if (failure)
12881304
throw new RuntimeException("Failure in BigIntegerTest.");

test/jdk/java/math/BigInteger/LargeValueExceptions.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,8 @@
3030
*/
3131
import java.math.BigInteger;
3232
import static java.math.BigInteger.ONE;
33+
import org.testng.ITestResult;
34+
import org.testng.annotations.AfterMethod;
3335
import org.testng.annotations.Test;
3436

3537
//
@@ -62,6 +64,13 @@ public class LargeValueExceptions {
6264
// Half BigInteger.MAX_MAG_LENGTH
6365
private static final int MAX_INTS_HALF = MAX_INTS / 2;
6466

67+
// Print the run time of each sub-test in milliseconds
68+
@AfterMethod
69+
public void getRunTime(ITestResult tr) {
70+
long time = tr.getEndMillis() - tr.getStartMillis();
71+
System.out.printf("Run time: %d ms%n", time);
72+
}
73+
6574
// --- squaring ---
6675

6776
// Largest no overflow determined by examining data lengths alone.

test/jdk/java/math/BigInteger/largeMemory/SymmetricRangeTests.java

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,6 +46,8 @@ public class SymmetricRangeTests {
4646
private static final BigInteger MAX_VALUE = makeMaxValue();
4747
private static final BigInteger MIN_VALUE = MAX_VALUE.negate();
4848

49+
private static final Random RANDOM = RandomFactory.getRandom();
50+
4951
private static BigInteger makeMaxValue() {
5052
byte[] ba = new byte[1 << 28];
5153
Arrays.fill(ba, (byte) 0xFF);
@@ -117,8 +119,7 @@ private static void testOverflowInBitSieve() {
117119
System.out.println("Testing overflow in BitSieve.sieveSingle");
118120
int bitLength = (5 << 27) - 1;
119121
try {
120-
Random random = RandomFactory.getRandom();
121-
BigInteger actual = new BigInteger(bitLength, 0, random);
122+
BigInteger actual = new BigInteger(bitLength, 0, RANDOM);
122123
throw new RuntimeException("new BigInteger(bitLength, 0, null).bitLength()=" + actual.bitLength());
123124
} catch (ArithmeticException e) {
124125
// expected
@@ -621,45 +622,64 @@ private static void testByteValueExact() {
621622
}
622623

623624
public static void main(String... args) {
624-
testOverflowInMakePositive();
625-
testBug8021204();
626-
testOverflowInBitSieve();
627-
testAdd();
628-
testSubtract();
629-
testMultiply();
630-
testDivide();
631-
testDivideAndRemainder();
632-
testBug9005933();
633-
testRemainder();
634-
testPow();
635-
testGcd();
636-
testAbs();
637-
testNegate();
638-
testMod();
639-
testModPow();
640-
// testModInverse();
641-
testShiftLeft();
642-
testShiftRight();
643-
testAnd();
644-
testOr();
645-
testXor();
646-
testNot();
647-
testSetBit();
648-
testClearBit();
649-
testFlipBit();
650-
testGetLowestSetBit();
651-
testBitLength();
652-
testBitCount();
653-
testToString();
654-
testToByteArrayWithConstructor();
655-
testIntValue();
656-
testLongValue();
657-
testFloatValue();
658-
testDoubleValue();
659-
testSerialization();
660-
testLongValueExact();
661-
testIntValueExact();
662-
testShortValueExact();
663-
testByteValueExact();
625+
// subset zero indicates to run all subsets
626+
int subset = Integer.valueOf(System.getProperty("subset",
627+
String.valueOf(1 + RANDOM.nextInt(4))));
628+
if (subset < 0 || subset > 4) {
629+
throw new RuntimeException("Unknown subset " + subset);
630+
}
631+
if (subset == 0)
632+
System.out.println("Testing all subsets");
633+
else
634+
System.out.println("Testing subset " + subset);
635+
636+
if (subset == 0 || subset == 1) {
637+
testOverflowInMakePositive();
638+
testBug8021204();
639+
testOverflowInBitSieve();
640+
testAdd();
641+
testSubtract();
642+
}
643+
if (subset == 0 || subset == 2) {
644+
testMultiply();
645+
testDivide();
646+
testDivideAndRemainder();
647+
testBug9005933();
648+
}
649+
if (subset == 0 || subset == 3) {
650+
testRemainder();
651+
testPow();
652+
testGcd();
653+
testAbs();
654+
testNegate();
655+
testMod();
656+
testModPow();
657+
// testModInverse();
658+
testShiftLeft();
659+
testShiftRight();
660+
testAnd();
661+
testOr();
662+
testXor();
663+
testNot();
664+
testSetBit();
665+
testClearBit();
666+
testFlipBit();
667+
testGetLowestSetBit();
668+
testBitLength();
669+
testBitCount();
670+
}
671+
if (subset == 0 || subset == 4) {
672+
testToString();
673+
testToByteArrayWithConstructor();
674+
testIntValue();
675+
testLongValue();
676+
testFloatValue();
677+
testDoubleValue();
678+
testSerialization();
679+
testLongValueExact();
680+
testIntValueExact();
681+
testShortValueExact();
682+
testByteValueExact();
683+
}
664684
}
665685
}

0 commit comments

Comments
 (0)