Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>According to my benchmarks, that code should easily be able to perform way better than 120 kb/s (I'm running on different hardware, but still).</p> <p>If you profile the code with <a href="http://developer.android.com/guide/developing/debugging/debugging-tracing.html" rel="nofollow">Traceview</a>, where is the time spent? If the bottleneck is FileInputStream.read(), think about:</p> <ul> <li>if some other app is using the sdcard at the same time as you, like a media indexing app or something. Sharing bandwidth with some other app will have an adverse effect on the sdcard reading performance of your app.</li> <li>If the sdcard itself is the problem. Try another sdcard or re-format the one you have.</li> </ul> <p>If the bottleneck is MessageDigest.update() (which I doubt), I guess you do need to look into a JNI solution. For your information, the SHA-1 implementation already is in native code (see <a href="https://github.com/android/platform_frameworks_base/blob/21e6e2de1f0062f949fcc52d0b4559dfa3246e0e/core/jni/android_message_digest_sha1.cpp" rel="nofollow">android_message_digest_sha1.cpp</a>), but maybe you can gain a speedup by avoiding some native &lt;-> Java copying.</p> <p><strong>Update 1 (Please ignore):</strong></p> <p>(Based on your profiling, the problem seems to be that you don't use Android's optimized <code>android.security.MessageDigest</code> but instead <code>java.security.MessageDigest</code>. Try <code>android.security.MessageDigest</code> instead. Both Android 2.2 and 2.3 have native SHA-1 implementations of <code>android.security.MessageDigest</code>.)</p> <p><strong>Update 2:</strong></p> <p>Sorry, I forgot about <code>android.security.MessageDigest</code> being internal. I now realize that I was also using <code>java.security.MessageDigest</code> in my benchmarking. I was running on Android 2.3 though, and it turns out the SHA-1 implementation of <code>java.security.MessageDigest</code> in Android 2.3 is in native code as well, while that appearently is not the case on Android 2.2.</p> <p>So the answer to your original question is: Yes, it is painfully slow in Android 2.2 due to a Java implementation but significantly faster in Android 2.3 due to an implementation in native code. You should see similar speedups on Android 2.2 if you use your own SHA-1 implementation in native code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload