1 // Test the performance of integer multiplication by implementing a 16-bit
4 function stringHash(string
)
6 // source: http://en.wikipedia.org/wiki/Java_hashCode()#Sample_implementations_of_the_java.lang.String_algorithm
8 var len
= string
.length
;
9 for (var index
= 0; index
< len
; index
++) {
10 h
= (((31 * h
) | 0) + string
.charCodeAt(index
)) | 0;
15 for (var i
= 0; i
< 10000; ++i
) {
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
;