Same result format for primes-alt.java

master
Vitaliy Filippov 2021-02-02 19:23:25 +03:00
parent 73cd9b123f
commit b07c3cec4c
2 changed files with 14 additions and 3 deletions

View File

@ -86,13 +86,24 @@ class IntList {
class PrimeNumbersBenchmarkApp {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
long periodTime = Long.parseLong(System.getenv("RUN_TIME"), 10) * 1000;
String periodTimeStr = System.getenv("RUN_TIME");
if (periodTimeStr == null)
periodTimeStr = "5";
long periodTime = Long.parseLong(periodTimeStr, 10) * 1000;
IntList res;
while ((System.currentTimeMillis() - startTime) < periodTime) {
int iterations = 0;
while ((System.currentTimeMillis() - startTime) < periodTime || iterations < 3) {
res = (new PrimeNumbersGenerator()).get_primes7(10000000);
System.out.format("Found %d prime numbers.\n", res.size());
iterations++;
}
long time = (System.currentTimeMillis() - startTime);
double per30 = time / 1000.0 / iterations * 30;
System.out.println(
"Java (IntList): "+iterations+" iterations in "+(Math.round(time/10.0)/100.0)+
" seconds = "+(Math.round(per30*100)/100.0)+" seconds per 30 iterations"
);
}
}

View File

@ -60,7 +60,7 @@ class PrimeNumbersBenchmarkApp {
long time = (System.currentTimeMillis() - startTime);
double per30 = time / 1000.0 / iterations * 30;
System.out.println(
"Java: "+iterations+" iterations in "+(Math.round(time/10.0)/100.0)+
"Java (ArrayList): "+iterations+" iterations in "+(Math.round(time/10.0)/100.0)+
" seconds = "+(Math.round(per30*100)/100.0)+" seconds per 30 iterations"
);
}