Skip to content

Commit

Permalink
adjust runtime for github testing
Browse files Browse the repository at this point in the history
  • Loading branch information
TilmanNeumann committed Dec 31, 2024
1 parent 48bb0ce commit 285af89
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package de.tilman_neumann.jml.factor;

import static org.junit.Assert.assertEquals;

import java.math.BigInteger;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -27,29 +29,35 @@
public class TestsetGeneratorTest {
private static final Logger LOG = LogManager.getLogger(TestsetGeneratorTest.class);

// the following parameters have been chosen to make the test run less than 10 seconds on github CI.
private static final int NCOUNT = 10;
private static final int MIN_BITS = 20;
private static final int MAX_BITS = 1000;
private static final int INCR_BITS = 10;

public static void main(String[] args) {
ConfigUtil.initProject();
Timer timer = new Timer();
int nCount = 100;
for (int bits = 20; ; bits+=10) {
for (int bits = MIN_BITS; bits<=MAX_BITS; bits+=INCR_BITS) {
long start = timer.capture();
BigInteger[] testNumbers = TestsetGenerator.generate(nCount, bits, TestNumberNature.MODERATE_SEMIPRIMES);
BigInteger[] testNumbers = TestsetGenerator.generate(NCOUNT, bits, TestNumberNature.MODERATE_SEMIPRIMES);
long end = timer.capture();
// Collect the true
// Collect the true bit lengths
Map<Integer, Integer> sizeCounts = new TreeMap<>();
for (BigInteger num : testNumbers) {
int bitlen = num.bitLength();
Integer count = sizeCounts.get(bitlen);
count = (count==null) ? Integer.valueOf(1) : count.intValue()+1;
sizeCounts.put(bitlen, count);
}
String generatedBitLens = "";
String generatedBitLengths = "";
for (int bitlen : sizeCounts.keySet()) {
generatedBitLens += sizeCounts.get(bitlen) + "x" + bitlen + ", ";
generatedBitLengths += sizeCounts.get(bitlen) + "x" + bitlen + ", ";
}
generatedBitLens = generatedBitLens.substring(0, generatedBitLens.length()-2);
LOG.info("Requesting " + nCount + " " + bits + "-numbers took " + TimeUtil.timeDiffStr(start, end) + " ms and generated the following bit lengths: " + generatedBitLens);
// Roughly 1/3 of generated numbers are one bit smaller than requested. No big problem though.
generatedBitLengths = generatedBitLengths.substring(0, generatedBitLengths.length()-2);
LOG.info("Requesting " + NCOUNT + " " + bits + "-numbers took " + TimeUtil.timeDiffStr(start, end) + " ms and generated the following bit lengths: " + generatedBitLengths);
// all generated test numbers have the requested bit length
assertEquals(NCOUNT + "x" + bits, generatedBitLengths);
}
}
}

0 comments on commit 285af89

Please sign in to comment.