Re: Hash functions

On 12/22/10 4:39 PM, Charles Pritchard wrote:
> It'd be nice to see an SHA1 JS test case setup for performance testing
> using recent APIs like ArrayBuffer.

Attached.  It uses a 16MB string as input.  I got the JS code off 
http://www.webtoolkit.info/javascript-sha1.html in case it matters.  I 
have no idea whether it's correct.

The SHA1 function is the original one.  The SHA1arr function uses typed 
arrays.  I do verify that the two return the same hash, just to make 
sure things are sane that way.

Note that there's still a bunch of inefficiency here for the "checksum a 
file" use case (e.g. the input is assumed to be a string and converted 
to a byte buffer by encoding the string as UTF-8).

My measurements show that the array version is about 2x faster than the 
string version in this case in both Firefox 4 and Google 10 dev.

Of course the string version in Firefox is about 2x faster than the 
array version in Chrome.  ;)

I know we definitely have more headroom in spidermonkey here.  Which is 
good, because even the array version in spidermonkey is a good bit 
slower than a C app.

-Boris

Received on Wednesday, 22 December 2010 23:49:35 UTC