Skip navigation.
Home

Heinz asks: Are you really Multi-Core?

Heinz writes The Java Specialists' Newsletter. In his latest issue he offers up a little program that will test CPU efficiency...

Issue #135 wrote:
One of the exercises that we do in the Java 5 course is to measure the CPU cycles that a thread has used, as opposed to elapsed time. If you have one CPU in your machine, then these should be roughly the same. However, when you have several CPUs in your machine, the CPU cycles should be a factor more than the elapsed time. The factor should never be more than the number of actual CPUs, and may be less when you either have other processes running, or too many threads per CPU. Also, as all good computer scientists know, you can never scale completely linearly on one machine, so as you approach a large number of CPUs, the factor will grow more slowly.

The program is attached below; here are the results...


Machine Name:	MacBook Pro 15"
  Machine Model:	MacBookPro1,1
  Processor Name:	Intel Core Duo
  Processor Speed:	2.16 GHz
  Number Of Processors:	1
  Total Number Of Cores:	2
  L2 Cache (per processor):	2 MB
  Memory:	2 GB
  Bus Speed:	667 MHz

java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-112)
Java HotSpot(TM) Client VM (build 1.5.0_06-64, mixed mode, sharing)

//2 Threads
Thread[Thread-1,5,main]: cpuTime = 2030798000
Thread[Thread-0,5,main]: cpuTime = 2057838000
Total elapsed time 2075417000
Total thread CPU time 4088636000
Factor: 1.97

//4 Threads
Thread[Thread-2,5,main]: cpuTime = 2047872000
Thread[Thread-1,5,main]: cpuTime = 2053035000
Thread[Thread-3,5,main]: cpuTime = 2048781000
Thread[Thread-0,5,main]: cpuTime = 2061850000
Total elapsed time 4212640000
Total thread CPU time 8211538000
Factor: 1.95

//6 Threads
Thread[Thread-2,5,main]: cpuTime = 2030112000
Thread[Thread-3,5,main]: cpuTime = 2045655000
Thread[Thread-5,5,main]: cpuTime = 2041642000
Thread[Thread-4,5,main]: cpuTime = 2034341000
Thread[Thread-1,5,main]: cpuTime = 2036640000
Thread[Thread-0,5,main]: cpuTime = 2060328000
Total elapsed time 6227081000
Total thread CPU time 12248718000
Factor: 1.97

Filename/TitleSize
MultiCoreTester.java1.36 KB