问题描述
我正在使用cygwin和Windows7编译本机代码.我在互联网上有很多优化技巧.
I'm compiling a native code using cygwin and Windows7.I got many optimization tips on Internet.
APP_OPTIM := release
ndk-build NDK_DEBUG=0
-DNDEBUG
LOCAL_CFLAGS += -O2
但是我无法完全理解如何在Application.mk和Android.mk上进行设置.通过应用以上技巧,我尝试了很多情况.但是,我不认为该优化会在我的本机代码中应用.
But I can't understand exactly how to set these on Application.mk and Android.mk.I tried many cases by applying the above tips.but, I don't think that the optimization is applied in my native code.
Application.mk
Application.mk
APP_PROJECT_PATH := $(shell pwd)
APP_MODULES := native_lib
APP_OPTIM := release
APP_BUILD_SCRIPT := Android.mk
APP_ABI := armeabi
Android.mk
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := lib/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := native_lib
LOCAL_SRC_FILES := nativeC.c \
AES/main.c \
AES/aes.c \
LOCAL_C_INCLUDES := ./lib
LOCAL_SHARED_LIBRARIES := crypto
LOCAL_CFLAGS += -O2
LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp
LOCAL_LDLIBS += -ldl
include $(BUILD_SHARED_LIBRARY)
我希望有很多评论.
此外,
首先,我尝试比较带有上述标志和不带有上述标志的情况. (例如,我使用Application.mk中的APP_OPTIM:=版本编译了程序,然后又没有它或使用APP_OPTIM:= debug进行了编译.)但是,我看不到运行速度的任何变化.
First, I tried to compare the cases between with the above flag and without it. (e.g. I compiled my program with APP_OPTIM := release in Application.mk, and then I compiled without it or with APP_OPTIM := debug, again.) But, I cannot see any change of the running speed.
第二,这是最重要的,我的程序比较了两个模块的速度. (为方便起见,我将它们称为模块A,B).模块A是预先构建的(在Android.mk中为libcrypto.so).我想将优化应用于模块B.首先,我比较了PC中模块A和B的速度测试(Visual Studio 2010).当我在PC上尝试模块A和B时,模块B的速度比A快.(当然,我已对模块A进行了预编译,并通过调用库来使用它.)现在,我将PC的程序移植到其中了.适用于Android.但是在Android中,模块B比A慢.
Second, this is the most important, My program compare the speed of two modules. (For convenience, I call them module A, B) Module A is prebuilt (which is libcrypto.so in Android.mk). And I want to apply optimization into Module B. First of all, I compared the speed test of module A and B in PC (Visual Studio 2010). When I tried module A and B in the PC, the module B is faster than A. (Of course, I precompiled the module A and I use it by calling the library.) Now I'm porting the my program for PC into it for Android. But in Android, the module B is too slower than A.
因此,我得出结论,这是没有优化的.
Therefore, I concluded that this is not optimized.
总之,
- 我比较了带有标志和没有标志之间的速度.
- 在PC上运行此程序时,预编译的模块A的速度比B,但是在Android中,这是完全相反的.
- I compared the speed between with the flag and without it.
- When running this program in PC, the precompiled module A is faster thanB, But in Android, it's totally opposite.
您认为我程序的问题是什么吗?预先谢谢你.
Do you thnk what my program's problem is ? Thank you in advance.
推荐答案
APP_OPTIM:=发布
将行APP_OPTIM := release
放入您的Application.mk文件
Put the line APP_OPTIM := release
into your Application.mk file
ndk-build NDK_DEBUG = 0
只需将NDK_DEBUG=0
作为参数传递给ndk-build
脚本.定义APP_OPTIM := release
后就不需要它.
Just pass the NDK_DEBUG=0
as a parameter to ndk-build
script. You don't need it once you define APP_OPTIM := release
.
-DNDEBUG
这应该进入您的LOCAL_CFLAGS
:
LOCAL_CFLAGS += -DNDEBUG
LOCAL_CFLAGS + = -O2
这实际上不是必需的,因为Android NDK已经定义了-O2
优化.
This is not required actually, since the Android NDK already defines -O2
optimization.
这篇关于如何使用android-ndk优化本机代码(速度优化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!