Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Hashing stuff
(version: 0)
Testing some hashing
Comparing performance of:
hashSum vs cyrb53
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var cfg = { "car": "resources/cars/141003", "color": "#AB2567", "angle": 6, "rims": "resources/rims/NISSAN_SUV2_kicks_2021_18_1500", "tyres": "resources/tyres/T4_18_1500", "tint": 25, "shadow": true, "height": 0, "plate": "", "background": "", "plateFilterQuality": 0, "partSelectionEnabled": true, "soloPart": "", "soloMode": "ghost" } function pad (hash, len) { while (hash.length < len) { hash = '0' + hash; } return hash; } function fold (hash, text) { var i; var chr; var len; if (text.length === 0) { return hash; } for (i = 0, len = text.length; i < len; i++) { chr = text.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; } return hash < 0 ? hash * -2 : hash; } function foldObject (hash, o, seen) { return Object.keys(o).sort().reduce(foldKey, hash); function foldKey (hash, key) { return foldValue(hash, o[key], key, seen); } } function foldValue (input, value, key, seen) { var hash = fold(fold(fold(input, key), toString(value)), typeof value); if (value === null) { return fold(hash, 'null'); } if (value === undefined) { return fold(hash, 'undefined'); } if (typeof value === 'object' || typeof value === 'function') { if (seen.indexOf(value) !== -1) { return fold(hash, '[Circular]' + key); } seen.push(value); var objHash = foldObject(hash, value, seen) if (!('valueOf' in value) || typeof value.valueOf !== 'function') { return objHash; } try { return fold(objHash, String(value.valueOf())) } catch (err) { return fold(objHash, '[valueOf exception]' + (err.stack || err.message)) } } return fold(hash, value.toString()); } function toString (o) { return Object.prototype.toString.call(o); } function sum (o) { return pad(foldValue(0, o, '', []).toString(16), 8); } function cyrb53(str, seed = 0) { let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed; for (let i = 0, ch; i < str.length; i++) { ch = str.charCodeAt(i); h1 = Math.imul(h1 ^ ch, 2654435761); h2 = Math.imul(h2 ^ ch, 1597334677); } h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909); h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909); return 4294967296 * (2097151 & h2) + (h1 >>> 0); };
Tests:
hashSum
const h = sum(cfg);
cyrb53
const h = cyrb53(JSON.stringify(cfg));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
hashSum
cyrb53
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 YaBrowser/24.1.0.0 Safari/537.36
Browser/OS:
Yandex Browser 24 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
hashSum
51194.5 Ops/sec
cyrb53
11670.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help explain the benchmark and its components. **Benchmark Definition:** The benchmark definition is a JSON object that contains two scripts: 1. `pad` function: This function takes a string `hash` and an integer `len` as input, pads the `hash` with leading zeros until it reaches the length of `len`, and returns the padded hash. 2. `fold` function: This function takes two inputs: a hash value `hash` and a text string `text`. It iteratively applies a folding operation to the hash value based on the ASCII values of each character in the text. The script preparation code defines an object `cfg` that contains various configuration parameters for a hypothetical car model. The `sum` function calculates the sum of a value using the `foldValue` function, which recursively folds the input value into a hash value. The `cyrb53` function is another folding function that takes a string as input and returns a 64-bit integer. **Individual Test Cases:** There are two individual test cases: 1. `hashSum`: This test case executes the script `const h = sum(cfg);`, which calculates the sum of the configuration object `cfg` using the `sum` function. 2. `cyrb53`: This test case executes the script `const h = cyrb53(JSON.stringify(cfg));`, which calculates the 64-bit integer hash value of the configuration object `cfg` using the `cyrb53` function. **Options Compared:** The two test cases compare different folding functions: 1. `hashSum`: Uses the `sum` function, which folds the input value into a hash value using a recursive process that pads the output with leading zeros. 2. `cyrb53`: Uses the `cyrb53` function, which is a non-recursive folding function that applies a combination of bitwise operations to the input string. **Pros and Cons:** * **hashSum**: Pros: + Easy to understand and implement + Fast execution (due to padding with leading zeros) Cons: + May not be suitable for large inputs due to padding overhead * `cyrb53`: Pros: + Efficient execution (no padding overhead) + Suitable for large inputs Cons: + More complex implementation compared to `hashSum` + Requires careful tuning of the folding constants **Other Considerations:** * The benchmark definition and test cases assume that the input configuration object `cfg` is not empty. * The `pad` function uses a simple padding strategy, which may not be suitable for all use cases (e.g., cryptographic applications). * The `cyrb53` function uses bitwise operations, which may require careful consideration of overflow and underflow conditions. Overall, the benchmark compares two different folding functions with distinct trade-offs between ease of implementation, efficiency, and robustness.
Related benchmarks:
lookup vs hash
Hashing
Hashing-2
string-hashcode3
Hash-sum string vs number 2
Comments
Confirm delete:
Do you really want to delete benchmark?