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 ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.