Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / regress / script-tests / big-int-mul.js
blobe48d8e627e32b1d9b2d809f54731637891af95ab
1 // Test the performance of integer multiplication by implementing a 16-bit
2 // string hash.
4 function stringHash(string)
6 // source: http://en.wikipedia.org/wiki/Java_hashCode()#Sample_implementations_of_the_java.lang.String_algorithm
7 var h = 0;
8 var len = string.length;
9 for (var index = 0; index < len; index++) {
10 h = (((31 * h) | 0) + string.charCodeAt(index)) | 0;
12 return h;
15 for (var i = 0; i < 10000; ++i) {
16 var result =
17 (stringHash("The spirit is willing but the flesh is weak.") *
18 stringHash("The vodka is strong but the meat is rotten.")) | 0;
19 if (result != -1136304128)
20 throw "Bad result: " + result;