I've noticed that
boolean isPrime= false;
System.out.println(item); //this kills performance
isPrime = checkIfPrime(i);
How to compare the cost of printing to screen to computation?
It is not possible. The cost (i.e elapsed time) of printing depends on where the "printed" characters go. I can trivially construct an example where the cost tends to infinity.
$ java YourClass | ( sleep 10000000000 )
After a few lines of output, the pipeline buffers will fill, and the
Are there any tricks to minimize this cost [Should I print one out of 10 records, or will this cost just as much because of conditional check]?
There is nothing that won't introduce another overhead; e.g. the overhead of testing whether or not to print.
The only way to entirely eliminate the print overhead is to not print at all while you are trying to measure performance.
What is my best way to proceed? Print each case? - Too slow. Let it run overnight? What if I missed some i++?
First run the program with the print statements to check that you are getting the right answers.
Then remove the print statements and run again to get your performance measures.