7

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

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

APP_PROJECT_PATH := $(shell pwd)
APP_MODULES := native_lib
APP_OPTIM := release
APP_BUILD_SCRIPT := Android.mk
APP_ABI := armeabi

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)

I hope many comments.


In Addition,

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.

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.

In summary,

  1. I compared the speed between with the flag and without it.
  2. When running this program in PC, the precompiled module A is faster than B, But in Android, it's totally opposite.

Do you thnk what my program's problem is ? Thank you in advance.

user2642459
  • 507
  • 3
  • 10
  • 18
  • 1
    How can you tell your compiled code isn't optimized? – krsteeve Aug 25 '13 at 18:52
  • I added the details in the below Answer. (In Addition...) – user2642459 Aug 26 '13 at 01:23
  • you can edit your question with more details, you shouldn't make an answer that isn't actually an answer. – krsteeve Aug 26 '13 at 01:27
  • 1
    Your PC is an `Intel` machine, while phone is an `ARM`. If you didn't write that code, if you don't know the details you can't make a claim like `Therefore, I concluded that this is not optimized.`. – auselen Aug 26 '13 at 08:22
  • My PC's CPU is "Intel COre 2 Quad Q6600" , while the phone's CPU is "ARMv7 Processor rev 1 (v7l)". If you need other information to solve my problems, I can give you any information. – user2642459 Aug 26 '13 at 14:24
  • optimization doesn't guarantee an increase in speed. As for @auselen 's suggestion - you're comparing two libraries running on different architectures - there might be differences in performance. The pre-complied library you are comparing against might even be compiled with different optimization on each platform. Unless you can control all these variables its not a valid test. – krsteeve Aug 26 '13 at 19:24

1 Answers1

13

APP_OPTIM := release

Put the line APP_OPTIM := release into your Application.mk file

ndk-build NDK_DEBUG=0

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

This should go into your LOCAL_CFLAGS:

LOCAL_CFLAGS += -DNDEBUG

LOCAL_CFLAGS += -O2

This is not required actually, since the Android NDK already defines -O2 optimization.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174