Skip to content

Commit 262fef2

Browse files
committed
Send non-benchmark output to stderr, make label unique
1 parent f9ebbaa commit 262fef2

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

PrimeCPP/solution_5/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscore/**
2+
*.exe

PrimeCPP/solution_5/PrimeCPP_array.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,23 +463,23 @@ class prime_sieve
463463
void printResults(bool showResults, double duration, size_t passes, size_t threads) const
464464
{
465465
if (showResults)
466-
cout << "2, ";
466+
cerr << "2, ";
467467

468468
size_t count = (Bits.size() >= 2); // Count 2 as prime if in range
469469
for (uint64_t num = 3; num <= Bits.size(); num += 2)
470470
{
471471
if (Bits.get(num))
472472
{
473473
if (showResults)
474-
cout << num << ", ";
474+
cerr << num << ", ";
475475
count++;
476476
}
477477
}
478478

479479
if (showResults)
480-
cout << "\n";
480+
cerr << "\n";
481481

482-
cout << "Passes: " << passes << ", "
482+
cerr << "Passes: " << passes << ", "
483483
<< "Threads: " << threads << ", "
484484
<< "Time: " << duration << ", "
485485
<< "Average: " << duration/passes << ", "
@@ -489,8 +489,8 @@ class prime_sieve
489489
<< "\n";
490490

491491
// Following 2 lines added by rbergen to conform to drag race output format
492-
cout << "\n";
493-
cout << "davepl_array;" << passes << ";" << duration << ";" << threads << ";algorithm=base,faithful=yes,bits=1\n";
492+
cerr << "\n";
493+
cout << "davepl_array_optimized;" << passes << ";" << duration << ";" << threads << ";algorithm=base,faithful=yes,bits=1\n";
494494
}
495495

496496
};
@@ -588,16 +588,16 @@ int main(int argc, char **argv)
588588

589589
if (!bQuiet)
590590
{
591-
cout << "Primes Benchmark (c) 2025 Dave's Garage - https://github.com/davepl/primes" << endl;
592-
cout << "--------------------------------------------------------------------------" << endl;
591+
cerr << "Primes Benchmark (c) 2025 Dave's Garage - https://github.com/davepl/primes" << endl;
592+
cerr << "--------------------------------------------------------------------------" << endl;
593593
}
594594

595595
if (bOneshot)
596-
cout << "Oneshot is on. A single pass will be used to simulate a 5 second run." << endl;
596+
cerr << "Oneshot is on. A single pass will be used to simulate a 5 second run." << endl;
597597

598598
if (bOneshot && (cSecondsRequested > 0 || cThreadsRequested > 1))
599599
{
600-
cout << "Oneshot option cannot be mixed with second count or thread count." << endl;
600+
cerr << "Oneshot option cannot be mixed with second count or thread count." << endl;
601601
return 0;
602602
}
603603

@@ -608,7 +608,7 @@ int main(int argc, char **argv)
608608

609609
if (!bQuiet)
610610
{
611-
printf("Computing primes to %llu on %d thread%s for %d second%s.\n",
611+
fprintf(stderr, "Computing primes to %llu on %d thread%s for %d second%s.\n",
612612
(unsigned long long)llUpperLimit,
613613
cThreads,
614614
cThreads == 1 ? "" : "s",
@@ -663,7 +663,7 @@ int main(int argc, char **argv)
663663
if (!bQuiet)
664664
checkSieve.printResults(bPrintPrimes, duration , cPasses, cThreads);
665665
else
666-
cout << cPasses << ", " << duration / cPasses << endl;
666+
cerr << cPasses << ", " << duration / cPasses << endl;
667667

668668
// On success return the count of primes found; on failure, return 0
669669

0 commit comments

Comments
 (0)