Android的NDK VS iOS版 - 性能问题 [英] Android NDK vs iOS - performance issue

查看:443
本文介绍了Android的NDK VS iOS版 - 性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在四处寻找解决方案unsuccesfully至少2天,以便我最后的希望,我决定在这里问问吧。

I've been looking around for solution at least 2 days unsuccesfully so as my last hope I decided to ask it here.

在这里工作,我们有使用我们要在iOS和Android同时运行一个OpenCV的C ++ code基地。原来,整个事情运行速度较慢在Android上,我无法找出原因。分析之后,我们得知道,调用C ++的code中的方法是在两个平台上完全相同的问题。在Android(三星Galaxy S4),它需要140-150毫秒来执行,而在iOS(iPhone 5)这是70ms的下面。
我读过有关优化本地code和使用不同的LOCAL_CFLAGS,但似乎并没有帮助一些文章。

Here at work we have a C++ code base using OpenCV that we want to run both on iOS and Android. It turned out that the whole thing runs slower on Android and I can't find out the reason. After profiling we got to know that the method that invokes the C++ code is the problem which is the exact same on both platforms. On Android(Samsung Galaxy S4) it takes 140-150 ms to execute while on iOS(iPhone 5) it's under 70ms. I've read some articles about optimizing native code and using different local_cflags but didn't seem to help.

这是一个需要被录取或者是有一个解决方案的事实?
谢谢你在前进,迈克

Is this a fact that needs to be admitted or is there a solution? Thank you in advance, Mike

推荐答案

您的经验与我很好的相关性。在(在我的案件中的Nexus 4)使用OpenCV的iOS和Android上我的经验:

Your experience correlates well with mine. In my experience using OpenCV on iOS and Android (in a Nexus 4 in my case):


  1. Android的一般速度较慢,如果你只使用单线程code。苹果CPU内核比我在Android手机上进行测试的核心速度(见很多手机的评论在网上提供),而最新的Andr​​oid手机有4个或更多的内核。在iOS上,OpenCV的使用GCD并行运行一些算法,但在Android上不使用OpenMP的(这是另类,但只有GCC 4.x的,而不是锵的作品)。可悲的是,使用OpenMP主线程之外是一种痛苦。 这个bug 仍然是$ P中$ psent在NDK的R10,所以要么你重新编译补丁工具链,或者你被卡住为主线,这是不是重计算最佳的选择上。

  1. Android is generally slower if you only use single-threaded code. Apple CPU cores are faster than any core I've tested on Android phones (see the many phone reviews available online), while latest Android phones have 4 or more cores. On iOS, OpenCV uses GCD to run a few algorithms in parallel, but on Android it doesn't use OpenMP (which is the alternative, but only works with GCC 4.x, and not Clang). Sadly, using OpenMP outside the main thread is a pain. This bug is still present in r10 of the NDK, so either you recompile the toolchain with the patches, or you are stuck on the main thread, which is not the best option for heavy computation.

OpenCV的Andr​​oid上,在默认情况下,自带Thumb指令,这是慢编译。我建议重新编译其设置ARM模式ON和NEON。

OpenCV on Android, by default, comes compiled with Thumb instructions, which are slower. I suggest recompiling it setting ARM mode ON, and NEON.

自动向量化标志。如果您在使用NDK GCC,你必须使用 -O3 ,加上 -funsafe-数学优化,以实现与NEON自动向量化。

Autovectorization flags. If you are using GCC on the NDK, you have to use -O3, plus -funsafe-math-optimizations to enable autovectorization with NEON.

CPU频率的限制。我的Nexus 4似乎比iOS的更加积极油门CPU的频率。我们已经看到在Android code时序大幅波动运行在iOS上非常稳定的计时,我们可以想到的唯一理由就是CPU的频率。的renderScript(见这个答案)马克塞斯CPU的频率,但电池寿命将遭受(你必须重写code)。

Throttling of the CPU frequency. My Nexus 4 seems to throttle the CPU frequency more enthusiastically than iOS. We've seen substantial swings in timings on Android code that runs at very stable timings on iOS, and the only reason we can think of is the CPU frequency. Renderscript (see this answer) maxes out the CPU frequency, but the battery life will suffer (and you have to rewrite the code).

这篇关于Android的NDK VS iOS版 - 性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆