Testing Your Computer Speed
This hour’s workshop is a Java program that performs a benchmark, a test that measures how fast computer hardware or software is operating. The Benchmark program uses a loop statement to repeatedly perform the following mathematical expression:
double x = Math.sqrt(index);
This statement calls the Math.sqrt() method to find the square root of a number. You learn how methods work during Hour 11, “Describing What Your Object Is Like.”
The benchmark you’re creating sees how many times a Java program can calculate a square root in one minute.
Use NetBeans to create a new empty Java file called Benchmark. Enter the text of Listing 8.2 and save the program when you’re done.
Listing 8.2. The Full Source Code of Benchmark.java ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access