Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently bought a new MacBook Pro which sometimes goes too fast. I frequently program for Mathematica, and on my old 2007 MacBook Pro I usually got a feeling for inefficient code when it runs sluggishly (that's when I decide "gee, I wrote some garbage code. Maybe I should spend a couple hours fine-tuning it"). However, on my new Mac, everything just runs zippy fast.

Is there a switch on the Mac that lets me slow down the CPU to, say, 1 GHz?

share|improve this question
    
Let's move the extended discussion to chat. – bmike Jan 5 at 17:07
    
You should have a look at apple.stackexchange.com/questions/24998/… – Max Ried Jan 6 at 19:39
    
I immediately remember this comic: xkcd.com/1172 – justhalf Jan 7 at 8:32
up vote 19 down vote accepted

I do not think it is possible to manipulate the minimum clock speed bar, simply because of the direct relation between power, frequency and the clock speed of a micro processor. Obviously the clock has a range, so for example for running simulations the system takes more power to run faster under the range, and then when you stop simulating you see the drop.

A Solution: Alternatively did you consider, running the programs within MAC OS but on an virtualizer (e.g., virtual box)? You can then limit the number of cores/RAM dedicating to running the second OS. In that case, the programs can forced to be run much slower; because the virtualizer has much lower resource. This will give you much more flexibility and in case of a failure, you can go back and change the virtualizer settings. More interestingly, you can bring the packaged settings that run on the virtualizer to another machine and run it there as well, by having the virtualizer there of course.

share|improve this answer
3  
VirtualBox is not an emulator. It's virtualizer. That's why it's called "VirtualBox". It virtualizes the CPU, it doesn't emulate it. QEmu, for example, is an emulator. (Although it can use virtualization, and will by default do so, if possible.) – Jörg W Mittag Jan 5 at 15:55
    
@JörgWMittag Noted. Changed, thanks. – Dave Rose Jan 5 at 17:13
1  
@JörgWMittag It's not a virtualizer. It's called type-2 hypervisor. – Max Ried Jan 6 at 19:31
1  
@DaveRose A vm is unnecessary because limits on processor count (affinity),memory, max cpu time, and many other resource linits can be set for a single process through the command line using unix utilities ulimit and sysctl - I do not remember if these utilities are installed by default you may need to install the command line developer tools through XCode. You would set ulimit and execute Mathematica from the shell – crasic Jan 7 at 5:19

If your concern is how efficient your software is, let me suggest a more engineering-oriented solution that will let you keep your MacBook running at full speed:

Use the profiler built into Mathematica. This will let you identify the parts of your computations that consume the most time without having to resort to seat-of-the-pants measurements that only work on slow hardware.

share|improve this answer
1  
How would this slow down the code on one Mac and not on another? It's good information, but doesn't seem relevant for this thread. – bmike Jan 5 at 21:08
    
@bmike This is good information. I didn't know about the Mathematica profiler. Although does not directly answer my question, it may help make it unnecessary (+1). Maybe would have been best left as a comment. – QuantumDot Jan 5 at 21:18
6  
@bmike it doesn't slow anything down, it addresses the issue the OP is actually trying to get at i.e. whether or not his/her Mathematica code is efficient. – nekomatic Jan 6 at 10:56

Profiling, as suggested in Blrfl's answer, is the more appropriate way to identify whether or not your Mathematica code is efficient. However if you really want to slow down its execution, you may be able to do this by changing the priority of the Mathematica process. I haven't tried this but you may find helpful information or software among these links:

Is there any way to set the priority of a process in Mac OS X?

How to permanently “renice” a process on Mac OS X (or iOS, etc)?

Appriority (formerly Renicer) by Northern Softworks

Some of those discussions are a bit old though, so you may need to experiment or search further to find what works on your Mac and OS X version. Also you may find the technique works more effectively if you set your Mac some other heavy processing task to run at the same time - converting a big video file, say.

share|improve this answer
    
Changing the priority of a process is not a guarantee that it will run slowly. It's just a hint to the operating system that if there's contention for processor time, processes with higher priorities get to go first. Without anything getting in its way, a low-priority process will run at full speed. – Blrfl Jan 6 at 14:09

Unfortunately, no. You can't alter the clock speed on Macintosh computers. They don't have a BIOS in the same way that Windows motherboards do, so there's no way the user can change the clock speed or fiddle with I/O stuff.

The reason for this is mostly because on a Mac, you don't need to manually change these things. The hardware is already pre-built and the OS knows what hardware it will/can be attached to.

share|improve this answer
    
Mac OS X CAN change the processor clock speed dynamically, for example to prioritise performance when plugged in versus battery life when on battery, so this isn't really correct - or at least if it is correct it's for the wrong reason i.e. the OS doesn't make this setting readily accessible. – nekomatic Jan 6 at 11:20
    
Good point. I edited the post to clarify this – JamEngulfer Jan 6 at 11:31

Yes, but it's not advised. The clock speed is controlled by the OS and the processor itself due to a number of factors, including processor load, temperature, and power availability.

If you reduce the battery to 10-20%, disconnect any external power source, and heat the laptop up to its maximum operating temperature, 95F (35C), it will certainly enter a lower power state, including reducing the processor clock significantly. A small heating pad, such as those used for back pain, below the laptop may be sufficient, and during the winter may be very comfortable for you.

However, it would be better to use the correct tools for performance tuning. Yes, you can simulate your old environment and thereby use your own internal clock, however the software you're using has clocks, timers, and other tools to understand the performance of your work. Given that you may likely upgrade again in several years, or you may use different computers and computing platforms in the intervening time, using crutches like emulators isn't a good long-term solution.

I suggest you instead make use of the built in tools. Regular use will allow you to use them without too much additional effort, so that you can integrate them into your software on the fly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.