Wednesday, May 30, 2012

[android-developers] Re: Problem with hashing speed

Thanks for spending some time in doing the tests!
but can you try including "byte[] f = md.digest();" inside your loop ?
in my test phone, add the digest() method will increase the timing by
40%.

But since your timings are much faster.. i think it could be due to
the dual core CPU of S2?
wow but i never expected the diffences in timings to be so huge.
do you happen to know any faster method of doing a hash?

THANKS A LOT!!

On May 31, 1:32 am, Harri Smått <har...@gmail.com> wrote:
> On May 30, 2012, at 6:16 PM, jing yang wrote:
>
> > I was testing the hash methods on a 16 bytes input, randomly generated
> > with the SecureRandom class.
>
> I'm still getting far more faster speeds on SGS2, around 4871ms for 524288 iterations. Roughly half of the time is spent generating random bytes, half calculating hash. My test code as below;
>
> MessageDigest md = null;
> SecureRandom sr = null;
> try {
>         MessageDigest md = MessageDigest.getInstance("SHA-256");
>         SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
>
>         byte seed[] = sr.generateSeed(128);
>         sr.setSeed(seed);
>
>         final long LOOP = 524288;
>         byte buf[] = new byte[16];
>
>         long time = SystemClock.uptimeMillis();
>         for (int i = 0; i < LOOP; ++i) {
>                 sr.nextBytes(buf);
>                 md.update(buf);
>         }
>         byte[] f = md.digest();
>         Log.d("timing", "time=" + (SystemClock.uptimeMillis() - time));} catch (Exception ex) {
>
>         ex.printStackTrace();
>
> }
>
> --
> H

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment