简体   繁体   English

是否可以使iOS模拟器的性能更像真正的iPhone?

[英]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. 苹果的iOS模拟器很棒-我一直使用它,因为它比在真实设备上运行要容易得多。 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. 因为它可以访问计算机的资源,所以我经常发现在iOS Simulator上运行良好(流畅)的代码并不总是能够在真实设备(本例中为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? 这个问题的标题说明了一切,但我再说一遍:是否有可能使iOS Simulator像真实的iOS设备一样执行?

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. 您可以使用“ nice”或“ renice”命令来降低模拟器的调度优先级,但是除非同时运行其他一些更高优先级的任务,否则它可能无济于事。

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. 其实并没有那么困难,最终您将对应用程序的真实性能有了一个更好的了解。

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. 这将生成内存警告,并导致iOS释放视图,否则尝试释放内存。 You can find all your viewDidUnload bugs at the same time ;-) 您可以同时找到所有viewDidUnload错误;-)

#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: 这是100ms的延迟:

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

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. 假设模拟器在您的代码上的测量速度提高了20倍。 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. 您可以尝试在应用程序委托中创建重复的NSTimer,然后在计时器回调nanosleep中每0.05秒将主线程纳米睡眠47.5毫秒(或其他间隔和比率),然后查看这是否会使“模拟”应用程序的速度降低到大约设备上的应用程序。 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. 在计时器回调中,您还可以监视应用程序进程的VM脏足迹,并在应用程序扩展一定数量时将其杀死。

Nope, that's how Apple sells dev licenses. 不,这就是Apple销售开发人员许可证的方式。

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. 您也许可以使用某种实用程序来限制CPU和RAM的运行,但这充其量只是一个猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM