Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Comparing 3 small hash types made in javascript
(version: 0)
Comparing performance of:
crc32 vs adler32 vs fletcher32
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
crc32
function crc32(s) { for (var t = [], i = 0; i < 256; i++) { for (var c = i, j = 0; j < 8; j++) { c = c & 1 ? 0xEDB88320 ^ c >>> 1 : c >>> 1; } t[i] = c; } for (i = -1, c = -1; ++i < s.length;) { c = c >>> 8 ^ t[c & 255 ^ s.charCodeAt(i)]; } return ((c ^ -1) >>> 0).toString(16).toUpperCase(); } crc32(Date.now())
adler32
function adler32(string) { const MOD_ADLER = 65521; let a = 1, b = 0; for (let i = 0; i < string.length; i++) { a = (a + string.charCodeAt(i)) % MOD_ADLER; b = (b + a) % MOD_ADLER; } return (b << 16 | a).toString(16); } adler32(Date.now())
fletcher32
function fletcher32(data) { for (let i = sum1 = sum2 = 0; i < data.length; i++) { sum1 = (sum1 + data.charCodeAt(i)) % 65535; sum2 = (sum2 + sum1) % 65535; } return (sum2 << 16 | sum1).toString(16); } fletcher32(Date.now())
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
crc32
adler32
fletcher32
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_5_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/137.0.7151.79 Mobile/15E148 Safari/604.1
Browser/OS:
Chrome Mobile iOS 137 on iOS 18.5.0
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
crc32
165351.1 Ops/sec
adler32
11101294.0 Ops/sec
fletcher32
5979114.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark measures the performance of three different hash function implementations in JavaScript: crc32, adler32, and fletcher32. These hash functions are used to generate a digital fingerprint or checksum for data. **Test Cases** Each test case represents one of the three hash function implementations: 1. **crc32**: This implementation uses a polynomial rolling hash algorithm. It's designed to be fast and efficient while maintaining a good distribution of output values. 2. **adler32**: This implementation uses a simple, non-cryptographic hash function that takes into account both the input data and the previous hash value (or sum). 3. **fletcher32**: This implementation uses another type of polynomial rolling hash algorithm, which is similar to crc32 but with some differences in how it handles overflow and updates. **Options Compared** The benchmark compares the performance of these three implementations under different conditions: * **Hash Function Type**: The three implementations are compared directly. * **Device Platform**: The results are reported for desktop platforms using Chrome 118, which ensures a consistent testing environment across all test cases. * **Operating System**: The results only report data for Windows operating systems. **Pros and Cons** Here's a brief summary of the pros and cons of each implementation: 1. **crc32**: * Pros: Fast, efficient, and widely used (e.g., in file compression algorithms like gzip). * Cons: May not provide good distribution of output values, which can affect security. 2. **adler32**: * Pros: Simple to implement, fast, and provides a good balance between speed and security. * Cons: Not as widely used or secure as crc32. 3. **fletcher32**: * Pros: Similar performance characteristics to crc32 but with some improvements in handling overflow and updates. * Cons: Less well-known than crc32, which may affect its adoption. **Libraries and Special JS Features** There are no specific libraries mentioned in the benchmark, as all three implementations are native JavaScript functions. However, it's worth noting that these hash functions can be used with various libraries or frameworks to provide additional functionality or features. **Special JS Feature:** None of the implementations rely on any special JavaScript features like async/await, Promises, or Web Workers, which is a good thing as it makes the benchmark more portable and run in most environments without issues. **Alternatives** Other alternatives for implementing hash functions include: * ** murmurhash**: A widely used, fast, and reliable non-cryptographic hash function. * **xxHash**: Another fast and reliable non-cryptographic hash function with a simple implementation. * **BLAKE2**: A cryptographically secure hash function that's designed to be fast and efficient. These alternatives may offer better performance or security characteristics depending on the specific use case, but they also require more computational resources.
Related benchmarks:
bitwise vs compare vs includes
fast Deep Equal vs JSON.stringify Equality Comparison for large arrays of nested numbers
fast Deep Equal vs JSON.stringify Equality Comparison for very large arrays of nested numbers
check if arrya
lodash.isEqual vs fast-deep-equal vs stable-hash-compare
Comments
Confirm delete:
Do you really want to delete benchmark?