I have a security library in C and try to import that into my Android project using NDK. The library depends on three other libraries: pbc, gmp, and openssl. I’ve built the first two libraries as static libraries and the last one as shared libraries.
I timed the encrypt() and decrypt() functions in my library.
On my laptop, it is:
- encrypt() 30ms
- decrypt() 160ms
On my Android device(Droid 2.2.3), it is:
- encrypt() 190ms
- decrypt() 1300ms
The time is only for calling those two functions from the C library. The JNI overhead is very small.
Is this expected?
Update:
Both encrypt() and decrypt() do not have any IO operation, mainly float point operation. And I compiled the code for armeabi-v7a.
First of all I would say that you are lucky – your port works only 8 times slower than laptop version. It is quite a good result for ARM-based platforms.
There are several reasons to be slower on ARM:
You can try the following things to improve the performance of you code:
-mfpu=vfpv3(or-mfpu=neon). It can slightly improve the speed of floating-point calculations because of doubled number of FPU registers.