title: How to optimize a native code with android-ndk (Speed Optimization)
body: <p>I'm compiling a native code using cygwin and Windows7.
  I got many optimization tips on Internet.</p>
  
  <pre><code>APP_OPTIM := release
  ndk-build NDK_DEBUG=0
  -DNDEBUG
  LOCAL_CFLAGS += -O2
  </code></pre>
  
  <p>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.</p>
  
  <p>Application.mk</p>
  
  <pre><code>APP_PROJECT_PATH := $(shell pwd)
  APP_MODULES := native_lib
  APP_OPTIM := release
  APP_BUILD_SCRIPT := Android.mk
  APP_ABI := armeabi
  </code></pre>
  
  <p>Android.mk</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I hope many comments.</p>
  
  <hr>
  
  <p><strong>In Addition,</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Therefore, I concluded that this is not optimized.</p>
  
  <p>In summary,</p>
  
  <ol>
  <li>I compared the speed between with the flag and without it. </li>
  <li>When running this program in PC, the precompiled module A is faster than
  B, But in Android, it's totally opposite.</li>
  </ol>
  
  <p>Do you thnk what my program's problem is ? Thank you in advance.</p>