eric.mitchell
eric.mitchell

Reputation: 8855

Is it possible to make the iOS Simulator perform more like a real iPhone?

Apple's iOS Simulator is great- I use it all the time because it is so much easier than running on a real device. It has a few drawbacks, though, one of which being it is too, well, powerful. Because it has access to the computer's resources, I often find that code that runs well (smoothly) on the iOS Simulator does not always run smoothly on a real device, in this case, my iPhone 4.

The title of this question says it all, but I'll say it again: Is it possible to make the iOS Simulator perform like a real iOS device?

Upvotes: 6

Views: 5513

Answers (4)

hotpaw2
hotpaw2

Reputation: 70743

You have to benchmark your particular application on both an actual device and the Simulator, as the difference varies by what your app does.

Say the Simulator measures 20X faster on your code. You could try creating a repeating NSTimer in the app delegate, and every 0.05 seconds in the timer callback nanosleep the main thread for 47.5 milliseconds (or other interval and ratio), and see if that slows the Simulated app down to about the speed of the app on your device. You may have to experiment with trial and error to get the right amount of "mud" in which to mire your app.

In the timer callback, you could also monitor the VM dirty footprint of your app's process, and kill the app if it expands by a certain number.

Upvotes: 1

progrmr
progrmr

Reputation: 77291

Place this in a few places in your app where you make use of a lot of memory space. This generates a memory warning and causes iOS to release views and otherwise try to free up memory. You can find all your viewDidUnload bugs at the same time ;-)

#if TARGET_IPHONE_SIMULATOR
    SEL memoryWarningSel = @selector(_performMemoryWarning);
    if ([[UIApplication sharedApplication] respondsToSelector:memoryWarningSel]) {
        NSLog(@"simulated memory warning");
        [[UIApplication sharedApplication] performSelector:memoryWarningSel];
    }
#endif

Maybe add a few delays here and there for good measure, but you'll have to decide where and how much to delay. Here is a 100ms delay:

#if TARGET_IPHONE_SIMULATOR
{ 
    const struct timespec delay = { 0, 100000000 }; 
    nanosleep(&delay, NULL);
}
#endif

Upvotes: 1

Caleb
Caleb

Reputation: 125037

You could use the 'nice' or 'renice' commands to change the lower the scheduling priority of the simulator, but it probably won't help much unless the are some other, higher priority tasks running at the same time.

Personally, I think you'd be better off spending your time getting the hang of running on the device. It's really not that difficult, and you'll end up with a much better idea of your app's true performance.

Upvotes: 4

Moshe
Moshe

Reputation: 58097

Nope, that's how Apple sells dev licenses.

You may be able to limit the CPU and RAM using some sort of utility to throttle it, but that's a guess at best.

Upvotes: 0

Related Questions