An algorithm to determine your processor performance

Good afternoon Guys (hot sun when i was writing these lines).
I was reading a programming book “Sams Teach Yourself Java in 24 Hours (Covering Java 7 and Android), 6th Edition” (without publicity, an amazing book to buy  🙂 and read B|  ) . Anyways, i fell on this algorithm that tests the performance(calculative) of a processor .
Seeming complex, but it’s as simple as thus : making the processor do a simple arithmetic calculation for a period (1 minute for this algorithm) and then counting the number of times(cycle) the processor does this calculation for the given period. Have a clue below :

caption of a netbeans code portion

caption of a netbeans code portion

– (line 5) “startTime” : a variable that get’s the current time in milliseconds
– (line 6) “endTime” : adds 60 000 milliseconds (1 minute) to the startTime
– (line 8 – 16) here is where the calculations takes place. The Mathematical operation used here is the square root (could be another).

so there’s this integer “index” (that arithmetically increments in line 14), for which we cyclically do the square root of , get the time of the square root calculation (in the variable “now” in line 10), until this time reaches one minute.

– (line 17) We display the number of loops the processor has done the square root.

The evaluation of the processor speed here is from the fact that a faster processor will do more loops in one minute than a less faster one. I used this to test 3 PCs that was around.

Here is the result of my “not-so-powerful-but-at-least-satisfactory-processor-speed” PC…. 😛 😛

execution results

execution results caption screen


Here’s the line to download the source code above (of the “Benchmark” class)


Thanks for reading 🙂



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s