impact of Intel Turbo Boost on frame rates

Hi guys, yesterday when I was benchmarking my game loop, I noticed that the cpu time spent on sleeping increases if I have a CPU intensive program running on the back ground. I guess the urge for processing power from the other program triggered the cpu to increased its clock frequency. I get similar result from both Intel i5 and i7 based machines.

My question is how can you accurately measure the time cpu spend on idle in a game loop? ??? It’s kinda important if you want to know how much more stuff you can throw at the cpu while maintain a constant frame rate.


ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long currentThreadId = Thread.currentThread().getId();

while(...) {
	// poll these values once a second
	ThreadInfo info = threadBean.getThreadInfo(id);
	long cpuTime = threadBean.getCurrentThreadCpuTime();
	long userTime = threadBean.getCurrentThreadUserTime();
	long waitTime = info.getWaitedTime();

	// calc diff with last second
}

I suspect you could also get this information with visualvm, nicely graphed at that.

Thanks very much for the help, however when I used ThreadMXBean to measure total cpu time spent in the game loop, I got strange results. As you can see from the chart below, the cpu time does not change from frame 4 to 6. Any suggestions?

[quote]0 0
1 78000500
2 93600600
3 109200700
4 124800800
5 124800800
6 124800800
7 140400900
8 156001000
9 171601100
10 187201200
11 202801300
12 202801300
13 202801300
14 218401400
15 234001500
16 249601600
17 265201700
18 265201700
19 265201700
20 265201700

[/quote]
Here is my code:




while(true) {
   threadBean = ManagementFactory.getThreadMXBean();

   System.out.println(frameIndex + "    " + threadBean.getCurrentThreadUserTime());

   doSomething();
}