Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Simple string compare vs MurmurHash on a large string
(version: 0)
Worst case large string comparison.
Comparing performance of:
=== vs murmurhash3_32_gc
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
let s10MB = "0123456789".repeat(1000*1000); var strings10MB = Array.from(Array(20)).map(o=>s10MB + String.fromCharCode(32+~~(Math.random()*96)))
Tests:
===
const s1 = strings10MB[~~(strings10MB.length*Math.random())]; const s2 = strings10MB[~~(strings10MB.length*Math.random())]; const b = s1 === s2;
murmurhash3_32_gc
function murmurhash3_32_gc(str) { var h1 = 0xdeadbeef; var k1 = 0; for (var i = 0; i < str.length; ++i) { k1 = str.charCodeAt(i); k1 = (k1 & 0x0000ffff) | ((k1 & 0xffff0000) >>> 16); k1 *= 0xcc9e2d51; k1 = (k1 << 15) | (k1 >>> 17); h1 ^= k1; h1 = (h1 << 13) | (h1 >>> 19); h1 = h1 * 5 + 0xe6546b64; } h1 ^= str.length; h1 ^= h1 >>> 16; h1 *= 0x85ebca6b; h1 ^= h1 >>> 13; h1 *= 0xc2b2ae35; h1 ^= h1 >>> 16; return h1 >>> 0; // Convert to unsigned 32-bit integer } const s1 = strings10MB[~~(strings10MB.length*Math.random())]; const s2 = strings10MB[~~(strings10MB.length*Math.random())]; const hash1 = murmurhash3_32_gc(s1); const hash2 = murmurhash3_32_gc(s2); const b = hash1 === hash2;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
===
murmurhash3_32_gc
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 OPR/117.0.0.0
Browser/OS:
Opera 117 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
===
817.3 Ops/sec
murmurhash3_32_gc
10.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Definition** The benchmark consists of two test cases: 1. `==` (Simple string compare) 2. `murmurhash3_32_gc` (MurmurHash algorithm) **Test Case 1: Simple String Compare (`==`)** In this test case, a large string (`s10MB`) is generated and split into two random strings (`s1` and `s2`). The comparison of these two strings using the `===` operator is measured. The pros of this approach are: * Easy to understand and implement. * Fast and simple implementation. However, there are some cons: * May not accurately represent real-world string comparison scenarios (e.g., case-insensitive comparison, ignoring whitespace). * Can be affected by caching or optimization techniques in the JavaScript engine. **Test Case 2: MurmurHash Algorithm (`murmurhash3_32_gc`)** This test case uses the MurmurHash algorithm to generate a 32-bit hash value from a given string. The same large string (`s10MB`) is used for both input strings, and the resulting hash values are compared. The pros of this approach are: * Provides a deterministic and high-quality hash function. * Can be useful for data integrity or uniqueness checks. However, there are some cons: * The implementation of the MurmurHash algorithm can be complex and error-prone. * May not provide meaningful results for very large input strings (e.g., 10MB). **Library Used:** In both test cases, the `strings10MB` array is generated using a repeating string (`"0123456789"`) concatenated with random whitespace characters. This library is used to generate the large input string. Other Considerations: * The benchmark uses a relatively small input size (10MB) for the strings. * The comparison operator (`===`) in Test Case 1 may not accurately represent real-world string comparison scenarios, such as case-insensitive comparison or ignoring whitespace. * The MurmurHash algorithm is designed to produce deterministic and high-quality hash values, but its performance can be affected by large input sizes. Alternatives: * Other hashing algorithms, such as SHA-256 or BLAKE2, could be used instead of MurmurHash. * Different string comparison operators (e.g., `==`, `===`, `>=`) could be used in Test Case 1 to evaluate their performance. * Larger input sizes (e.g., 100MB) could be used to evaluate the performance of these algorithms on very large strings. Overall, this benchmark provides a good starting point for evaluating the performance of simple string comparison and hashing algorithms in JavaScript.
Related benchmarks:
large string comparison
large string comparison benchmark
Simple string compare vs SHA-1 hash
large string comparison1
Comments
Confirm delete:
Do you really want to delete benchmark?