Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
large string comparison
(version: 0)
Worst case large string comparison.
Comparing performance of:
1MB string comparison vs 2MB string comparison vs 10MB string comparison
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
let s1MB = "0123456789".repeat(1000*100); var strings1MB = Array.from(Array(20)).map(o=>s1MB + String.fromCharCode(32+~~(Math.random()*96))) let s2MB = "0123456789".repeat(1000*200); var strings2MB = Array.from(Array(20)).map(o=>s2MB + String.fromCharCode(32+~~(Math.random()*96))) let s10MB = "0123456789".repeat(1000*1000); var strings10MB = Array.from(Array(20)).map(o=>s10MB + String.fromCharCode(32+~~(Math.random()*96)))
Tests:
1MB string comparison
const s1 = strings1MB[~~(strings1MB.length*Math.random())]; const s2 = strings1MB[~~(strings1MB.length*Math.random())]; const b = s1 === s2;
2MB string comparison
const s1 = strings2MB[~~(strings2MB.length*Math.random())]; const s2 = strings2MB[~~(strings2MB.length*Math.random())]; const b = s1 === s2;
10MB string comparison
const s1 = strings10MB[~~(strings10MB.length*Math.random())]; const s2 = strings10MB[~~(strings10MB.length*Math.random())]; const b = s1 === s2;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
1MB string comparison
2MB string comparison
10MB string comparison
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
1MB string comparison
66170.2 Ops/sec
2MB string comparison
10447.4 Ops/sec
10MB string comparison
1238.8 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares the performance of JavaScript's strict equality operator (`===`) when comparing large strings. **Here's a breakdown:** * **Options Compared:** The benchmark tests string comparison for three different string sizes: 1MB, 2MB, and 10MB. Each test randomly selects two strings from the predefined arrays of that size and compares them using `===`. * **Pros/Cons:** * **`===` (Strict Equality):** This operator checks if both values are of the same type *and* have the same value. It's generally considered the most reliable way to compare strings in JavaScript, as it avoids potential issues with type coercion that can occur with loose equality (`==`). * **Alternatives:** While `===` is generally preferred, there are other string comparison methods like using a regular expression or iterating through each character individually. However, these methods are usually less efficient than `===`. The benchmark likely focuses on `===` as it's the standard and often most performant approach for basic string equality checks. **Considerations:** * **String Size:** The benchmark demonstrates that larger strings take significantly longer to compare due to increased memory access and processing time. * **Implementation Details:** The benchmark doesn't delve into specific JavaScript engine optimizations that might influence performance (e.g., caching, compiler techniques). Real-world performance can vary based on the underlying JavaScript runtime environment. **Other Alternatives:** * For more complex comparisons or if you need to handle different string formats, consider using specialized libraries like Lodash or Underscore.js, which offer optimized functions for various string manipulation tasks. Let me know if you have any other questions!
Related benchmarks:
large string comparison benchmark
Simple string compare vs MurmurHash on a large string
large string comparison1
large string size comparison
Comments
Confirm delete:
Do you really want to delete benchmark?