Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Hash Test
(version: 2)
Comparing performance of:
regular vs asm
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var alpha = "abcdefghijklmnopqrstuvwxyz"; var test = []; for(var i = 0; i < 100000; i++){ test.push(alpha[Math.random() * 26]); } var testStr = test.join(""); function djb2Regular(str) { var hash = 5381; if (str == null) { return hash; } for (var i = 0; i < str.length; i++) { var char = str.charCodeAt(i); hash = ((hash << 5) + hash) + char; /* hash * 33 + c */ } return hash; } function hashModule(stdlib, foreign, heap) { "use asm"; function djb2Asm(str) { var hash = 5381; if (str == null) { return hash; } var length = str.length | 0; for (var i = 0 | 0; i < length; i++) { var char = str.charCodeAt(i) | 0; hash = (((hash << 5) + hash) + char) | 0; /* hash * 33 + c */ } return hash | 0; } return { hash: djb2Asm }; } var djb2Asm = hashModule(window, null, null).hash;
Tests:
regular
djb2Regular(testStr)
asm
djb2Asm(testStr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regular
asm
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 137 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
regular
82613872.0 Ops/sec
asm
84981920.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition Json** The provided benchmark definition json represents a hash test, which is designed to measure the performance of two different hashing functions: `djb2Regular` and `hashModule`. The script preparation code generates a large string of random characters, which is then used as input for both hashing functions. The html preparation code is empty in this case. **Options Compared** The benchmark compares two options: 1. **Regular**: This option uses the `djb2Regular` function, which is a JavaScript implementation of the djb2 algorithm. It's a widely used and well-known hashing function. 2. **ASM**: This option uses the `hashModule`, specifically the `djb2Asm` function, which is an assembly language implementation of the djb2 algorithm. It's optimized for performance, especially on platforms that support assembly language. **Pros and Cons** **Regular (djb2Regular)** Pros: * Wide adoption and familiarity * Well-documented and widely tested * Easy to implement in JavaScript Cons: * May not be as fast as the assembly language implementation due to overhead of JavaScript interpreter **ASM (hashModule)** Pros: * Optimized for performance, especially on platforms that support assembly language * Can provide better performance compared to the regular implementation Cons: * Requires platform-specific knowledge and expertise in assembly language programming * May not be compatible with all JavaScript environments **Other Considerations** * The benchmark is run on a Linux desktop platform using Firefox 115. * The `hashModule` function uses the `use asm` directive, which enables the use of assembly language code. This requires support for assembly language in the browser or runtime environment. **Library and Its Purpose** In this case, there isn't a separate library being used. However, the `djb2Asm` function is an implementation of the djb2 algorithm using assembly language. It's not a standard library function, but rather a custom implementation optimized for performance. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. The code uses standard JavaScript features and syntaxes to implement the hashing functions. **Alternatives** If you're looking for alternative hashing algorithms or implementations, some popular options include: * **MD5**: A widely used but insecure hashing algorithm. * **SHA-256**: A secure hashing algorithm commonly used for data integrity and authenticity. * **BLAKE2**: A fast and secure hashing algorithm designed for cryptographic purposes. MeasureThat.net also provides a range of other benchmarks and tests, including web page load times, image compression, and more.
Related benchmarks:
Hashing-2
string-hashcode
string-hashcode2
Hashes: JavaString, DJB2, Cyr53
Comments
Confirm delete:
Do you really want to delete benchmark?