jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
This does a simple comparison of a number of JS implementations of the MD5 algorithm. Based on MD5 Shootout.
Uses the following routines...
Tiny-SHA1 https://code.google.com/p/tiny-sha1/
PHP.JS SHA1 http://phpjs.org/functions/sha1/
SHA1 in 1K http://antimatter15.com/wp/2010/01/javascript-sha1-and-sha256-in-1-kb/
Paul Johnston's SHA1 http://pajhome.org.uk/crypt/md5/sha1.html
Also, it tests the speed of various UTF-8 encoding routines, to see if that makes any performance difference.
PHP.JS UTF-8 Encode http://phpjs.org/functions/utf8_encode/
jsbase64 toUtf8 http://jsbase64.codeplex.com/
Chromium's UTF-8 Encode https://chromium.googlesource.com/chromium/blink/+/282cb8d52d7f2b6ba34db7d186a2604d0833e948/LayoutTests/fast/encoding/api/utf-round-trip.html
ecmanaut's UTF-8 Encoding http://ecmanaut.blogspot.com.au/2006/07/encoding-decoding-utf8-in-javascript.html
JSHashes UTF-8 Encoding https://github.com/h2non/jshashes/blob/master/hashes.js
<script type="text/javascript">/*<![CDATA[*/
var hash, shaObj, utf;
function utf8_encode(a){if(null===a||"undefined"==typeof a)return"";var d,e,b=a+"",c="",f=0;d=e=0,f=b.length;for(var g=0;f>g;g++){var h=b.charCodeAt(g),i=null;if(128>h)e++;else if(h>127&&2048>h)i=String.fromCharCode(192|h>>6,128|63&h);else if(h&!0)i=String.fromCharCode(224|h>>12,128|63&h>>6,128|63&h);else{if(h&!0)throw new RangeError("Unmatched trail surrogate at "+g);var j=b.charCodeAt(++g);if(j&!0)throw new RangeError("Unmatched lead surrogate at "+(g-1));h=((1023&h)<<10)+(1023&j)+65536,i=String.fromCharCode(240|h>>18,128|63&h>>12,128|63&h>>6,128|63&h)}null!==i&&(e>d&&(c+=b.slice(d,e)),c+=i,d=e=g+1)}return e>d&&(c+=b.slice(d,f)),c};
var PHP = {
JS : {
SHA1 : function(a){var d,e,f,m,n,o,p,q,r,b=function(a,b){var c=a<<b|a>>>32-b;return c},c=function(a){var c,d,b="";for(c=7;c>=0;c--)d=15&a>>>4*c,b+=d.toString(16);return b},g=new Array(80),h=1732584193,i=4023233417,j=2562383102,k=271733878,l=3285377520;a=utf8_encode(a);var s=a.length,t=[];for(e=0;s-3>e;e+=4)f=a.charCodeAt(e)<<24|a.charCodeAt(e+1)<<16|a.charCodeAt(e+2)<<8|a.charCodeAt(e+3),t.push(f);switch(s%4){case 0:e=2147483648;break;case 1:e=8388608|a.charCodeAt(s-1)<<24;break;case 2:e=32768|(a.charCodeAt(s-2)<<24|a.charCodeAt(s-1)<<16);break;case 3:e=128|(a.charCodeAt(s-3)<<24|a.charCodeAt(s-2)<<16|a.charCodeAt(s-1)<<8)}for(t.push(e);14!=t.length%16;)t.push(0);for(t.push(s>>>29),t.push(4294967295&s<<3),d=0;d<t.length;d+=16){for(e=0;16>e;e++)g[e]=t[d+e];for(e=16;79>=e;e++)g[e]=b(g[e-3]^g[e-8]^g[e-14]^g[e-16],1);for(m=h,n=i,o=j,p=k,q=l,e=0;19>=e;e++)r=4294967295&b(m,5)+(n&o|~n&p)+q+g[e]+1518500249,q=p,p=o,o=b(n,30),n=m,m=r;for(e=20;39>=e;e++)r=4294967295&b(m,5)+(n^o^p)+q+g[e]+1859775393,q=p,p=o,o=b(n,30),n=m,m=r;for(e=40;59>=e;e++)r=4294967295&b(m,5)+(n&o|n&p|o&p)+q+g[e]+2400959708,q=p,p=o,o=b(n,30),n=m,m=r;for(e=60;79>=e;e++)r=4294967295&b(m,5)+(n^o^p)+q+g[e]+3395469782,q=p,p=o,o=b(n,30),n=m,m=r;h=4294967295&h+m,i=4294967295&i+n,j=4294967295&j+o,k=4294967295&k+p,l=4294967295&l+q}return r=c(h)+c(i)+c(j)+c(k)+c(l),r.toLowerCase()}
}
}
var SHA1in1K = function(l){function p(b,a){return b<<a|b>>>32-a}l+="";for(var n=Math,c=[1518500249,1859775393,2400959708,3395469782,1732584193,4023233417,2562383102,271733878,3285377520,4294967295],s=n.ceil(l.length/4)+2,q=n.ceil(s/16),g=[],a=0,h=[],j,d,e,f,m,i,b,k;a<q;a++){g[a]=[];for(k=0;k<16;k++){function o(b,c){return l.charCodeAt(a*64+k*4+b)<<c}g[a][k]=o(0,24)|o(1,16)|o(2,8)|o(3,0)}}i=l.length*8-8;a=q-1;g[a][14]=i/(c[9]+1);g[a][14]=n.floor(g[a][14]);g[a][15]=i&c[9];for(a=0;a<q;a++){for(b=0;b<16;b++)h[b]=g[a][b];for(b=16;b<80;b++)h[b]=p(h[b-3]^h[b-8]^h[b-14]^h[b-16],1);j=c[4];d=c[5];e=c[6];f=c[7];m=c[8];for(b=0;b<80;b++){var r=n.floor(b/20),t=p(j,5)+(r<1?d&e^~d&f:r==2?d&e^d&f^e&f:d^e^f)+m+c[r]+h[b]&c[9];m=f;f=e;e=p(d,30);d=j;j=t}c[4]+=j;c[5]+=d;c[6]+=e;c[7]+=f;c[8]+=m}i="";for(z=4;z<9;z++)for(a=7;a>=0;a--)i+=((c[z]&c[9])>>>a*4&15).toString(16);return i};
function jsSHA(srcString){jsSHA.charSize=8;jsSHA.b64pad ="";jsSHA.hexCase=0;var sha1=null;var str2binb=function(str){var bin=[];var mask =(1 << jsSHA.charSize)- 1;var length=str.length*jsSHA.charSize;for(var i=0;i<length;i += jsSHA.charSize){bin[i >> 5] |=(str.charCodeAt(i/jsSHA.charSize)& mask)<<(32-jsSHA.charSize-i%32);}return bin;};var strBinLen=srcString.length*jsSHA.charSize;var strToHash=str2binb(srcString);var binb2hex=function(binarray){var hex_tab=jsSHA.hexCase?"0123456789ABCDEF":"0123456789abcdef";var str="";var length=binarray.length*4;for(var i=0;i<length;i++){str += hex_tab.charAt((binarray[i >> 2] >>((3-i%4)* 8+4))& 0xF)+ hex_tab.charAt((binarray[i >> 2] >>((3-i%4)* 8))& 0xF);}return str;};var binb2b64=function(binarray){var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var str="";var length=binarray.length*4;for(var i=0;i<length;i += 3){var triplet =(((binarray[i >> 2] >> 8 *(3-i%4))& 0xFF)<< 16)|(((binarray[i+1 >> 2] >> 8 *(3 -(i+1)% 4))& 0xFF)<< 8)|((binarray[i+2 >> 2] >> 8 *(3 -(i+2)% 4))& 0xFF);for(var j=0;j<4;j++){if(i*8+j*6>binarray.length*32){str += jsSHA.b64pad;}else{str += tab.charAt((triplet >> 6 *(3-j))& 0x3F);}}}return str;};var rotl=function(x,n){if(n<32){return(x << n)|(x >>>(32-n));}else{return x;}};var parity=function(x,y,z){return x ^ y ^ z;};var ch=function(x,y,z){return(x & y)^(~x & z);};var maj=function(x,y,z){return(x & y)^(x & z)^(y & z);};var safeAdd=function(x,y){var lsw =(x & 0xFFFF)+(y & 0xFFFF);var msw =(x >>> 16)+(y >>> 16)+(lsw >>> 16);return((msw & 0xFFFF)<< 16)|(lsw & 0xFFFF);};var coreSHA1=function(){var W=[];var a,b,c,d,e;var T;var H=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0];var K=[0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6];var message=strToHash.slice();message[strBinLen >> 5] |= 0x80 <<(24-strBinLen%32);message[((strBinLen+1+64 >> 9)<< 4)+ 15]=strBinLen;var appendedMessageLength=message.length;for(var i=0;i<appendedMessageLength;i += 16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];for(var t=0;t<80;t++){if(t<16){W[t]=message[t+i];}else{W[t]=rotl(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16],1);}if(t<20){T=safeAdd(safeAdd(safeAdd(safeAdd(rotl(a,5),ch(b,c,d)),e),K[t]),W[t]);}else if(t<40){T=safeAdd(safeAdd(safeAdd(safeAdd(rotl(a,5),parity(b,c,d)),e),K[t]),W[t]);}else if(t<60){T=safeAdd(safeAdd(safeAdd(safeAdd(rotl(a,5),maj(b,c,d)),e),K[t]),W[t]);}else{T=safeAdd(safeAdd(safeAdd(safeAdd(rotl(a,5),parity(b,c,d)),e),K[t]),W[t]);}e=d;d=c;c=rotl(b,30);b=a;a=T;}H[0]=safeAdd(a,H[0]);H[1]=safeAdd(b,H[1]);H[2]=safeAdd(c,H[2]);H[3]=safeAdd(d,H[3]);H[4]=safeAdd(e,H[4]);}return H;};this.getHash=function(format){var formatFunc=null;if(sha1===null){sha1=sha1=coreSHA1();}switch(format){case "HEX":formatFunc=binb2hex;break;case "B64":formatFunc=binb2b64;break;default:return "FORMAT NOT RECOGNIZED";}return formatFunc(sha1);};}
function toUtf8(a){var d,b=-1,c=a.length,e=[];if(/^[\x00-\x7f]*$/.test(a))for(;++b<c;)e.push(a.charCodeAt(b));else for(;++b<c;)d=a.charCodeAt(b),128>d?e.push(d):2048>d?e.push(192|d>>6,128|63&d):e.push(224|d>>12,128|63&d>>6,128|63&d);return e}
function encode_utf8(a){var d,b=unescape(encodeURIComponent(a)),c=[];for(d=0;d<b.length;d+=1)c.push(b.charCodeAt(d));return c}
function ecmanaut_encode_utf8(s) { return unescape(encodeURIComponent(s)); }
function jshashes_utf8Encode(a){var b,c,f,d="",e=-1;if(a&&a.length)for(f=a.length;(e+=1)<f;)b=a.charCodeAt(e),c=f>e+1?a.charCodeAt(e+1):0,b>=55296&&56319>=b&&c>=56320&&57343>=c&&(b=65536+((1023&b)<<10)+(1023&c),e+=1),127>=b?d+=String.fromCharCode(b):2047>=b?d+=String.fromCharCode(192|31&b>>>6,128|63&b):65535>=b?d+=String.fromCharCode(224|15&b>>>12,128|63&b>>>6,128|63&b):2097151>=b&&(d+=String.fromCharCode(240|7&b>>>18,128|63&b>>>12,128|63&b>>>6,128|63&b));return d}
/*]]>*/</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js"></script>
<script src="https://tiny-sha1.googlecode.com/svn/trunk/tinySHA1.js">
<script src="https://pajhome.googlecode.com/svn-history/r124/trunk/crypt/md5/sha1.js"></script>
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
CryptoJS SHA1 |
| ready |
Tiny-SHA1 |
| ready |
PHP.JS SHA1 |
| ready |
SHA1 in 1KB |
| ready |
PAJ's SHA-1 |
| ready |
JSSHA |
| ready |
PHP.JS utf8_encode |
| ready |
jsbase64 toUtf8 |
| ready |
Chromium's UTF-8 Encode |
| ready |
Ecmanaut's UTF-8 Encode |
| ready |
JSHashes UTF-8 Encode |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.