11

I'm trying to optimize several bottlenecks on an application which is supposed to run on a really wide range of CPUs and architectures (some of them very close to embeded devices).

The results of my profiler, however, aren't really significant because of the speed of my CPU. Is there any way (preferably under Windows or Mac OS X) to limit the speed of my CPU for profiling purposes?

I've thought about using a virtual machine, but haven't found any with such functionality.

Vicent Marti
  • 7,203
  • 6
  • 30
  • 34

6 Answers6

4

This works well and supports multicore. http://www.cpukiller.com/

Tony BenBrahim
  • 7,040
  • 2
  • 36
  • 49
2

It's a common misconception that you need to know how fast your code is to know where your performance problems are. That confuses problem-finding with problem-measurement.

This is the method I use.

If there is some wasteful logic in the program, it will be wasteful no matter what CPU runs it.

What you need to know is where it is. For measurement, you don't need to know how big it is; you only need to know that it is big enough to need to be fixed.

Usually there are a number of problems, of different sizes. You will probably find the biggest ones first, but no matter what order you fix them in, each one you fix will make it easier to find the remaining ones, because they will take a larger percentage.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • You do have a point, but first of all you must find out *if you have a problem*. If you have inefficient code, but the inefficiencies are dwarved by I/O wait times, there's no point optimizing it. So the relations between the speeds of the system components matter for performance testing, and that's why he needs to slow down the CPU. – sleske Nov 30 '10 at 11:58
  • @sleske: That's why I don't like to make too much of a distinction between CPU time and blocked time. A performance bug can consist of too much of either one, but the OP didn't really mention I/O. My point is, doing something with 10 instructions, where 1 would do the job, is as wasteful at 1ghz as at 1hz. I think percents are more important than times, for the purpose of isolating the waste. – Mike Dunlavey Nov 30 '10 at 13:11
  • 1
    @sleske: ... I don't think I said it very well. Here's an example (http://stackoverflow.com/questions/926266/performance-optimization-strategies-of-last-resort/927773#927773) where there were a series of performance problems, ranging in size over about 2 orders of magnitude, one of which was an I/O problem. After removing some bigger ones, it came to a point where the I/O was biggest. If the CPU ran at a different speed, that would just come at a different point. – Mike Dunlavey Nov 30 '10 at 13:19
  • True, and good example. "that would just come at a different point": exactly my point. If the targe system has a slow CPU, it's more economical to optimize for CPU usage first, and if that's what the OP wants to do, he/she needs a "slow" CPU. Otherwise he/she'll do loads of I/O optimizations, only to find that I/O times are dwarved by CPU runtime on the target system. – sleske Nov 30 '10 at 13:47
  • @sleske: I think we're in violent agreement :) I was only trying to make the point that, *if you can ignore I/O*, speed of CPU makes no difference if the goal is to make the code as fast as possible. I only say that because there is so much emphasis on measuring speed, and the accuracy thereof, when that is only good for evaluating the results of tuning, and of little value in locating the things to tune. Anyway, you've made good points, and thanks. – Mike Dunlavey Nov 30 '10 at 15:33
1

I'm afraid I don't know any answer other than to start looking around in your area for old hardware. The CPU isn't the only variable that can (usually) affect things. L1/L2 cache size, memory bus speed, memory speed/latency, hard drive speed, etc. are all significant factors in many applications.

infinitetape
  • 1,349
  • 12
  • 8
0

I've thought about using a virtual machine, but haven't found any with such functionality.

Why do you need a VM that explicitly offers that functionality? Just limit the CPU usage of the VM in the host OS (where it is just a regular process). That should have exactly the same effect.

You can do this e.g. using cpulimit on Linux; similar solutions exist for MS Windows.

sleske
  • 81,358
  • 34
  • 189
  • 227
  • This make get a very unsmooth cpu, e.g. fast for half a second, then nothing for next half second - depending on how the VM system works. – Ian Ringrose May 13 '11 at 08:15
0

There was an app on Downloadsquad.com recently. I dont remember the name of it but it did some fun stiff woth processors and task manager. It may have only been to manage what apps are on what cpu but maybe it would give you this. I will try to look for it this afternoon, and respond back if I find it.

Adam Lerman
  • 3,369
  • 9
  • 42
  • 53
0

Many profilers (for example oprofile - but thats linux only) let you set the frequency that they collect data. See if your profiler supports this, and if not try a different one that does.

Greg Rogers
  • 35,641
  • 17
  • 67
  • 94
  • I believe he wants to slow down the CPU so the relation between CPU speed and speed of other operations (such as I/O, user input ...) is closer to the relations experienced on old systems. I don't see how increasing collection frequency would help there. – sleske Nov 30 '10 at 11:56
  • @sleske I assumed he meant the CPU was so fast that very few profile samples were collected, so no meaningful data was returned. – Greg Rogers Dec 22 '10 at 15:43