Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Substring Test
(version: 0)
Comparing performance of:
Map- best vs Search- best vs Includes -best vs Map - random vs Search- random vs Includes- random vs Map -bad vs Search-bad vs Includes -bad
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function createString(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; var charactersLength = characters.length; for (let i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } let length = 500 var randomWord1 = createString(length) var randomWord2 = createString(length) var bestWord1 = 'a' var bestWord2 = 'a' var badWord1 = ('a'.repeat(length) + 'g') var badWord2 = ('x'.repeat(length) + 'g') function checkMap(string1, string2) { let seenMap = new Map() for(let letter of string1) { if(!seenMap.has(letter)) { if(string2.includes(letter)) return "YES" seenMap.set(letter, true) } } return "NO" } function checkSearch(string1,string2){ for(let letter of string1){ if(string2.search(string1.substring(letter))!=-1){ return "YES"; } } return "NO"; } function checkIncludes(string1,string2){ for(let letter of string1) { if(string2.includes(letter))return "YES"; } return "NO"; }
Tests:
Map- best
checkMap(bestWord1, bestWord2)
Search- best
checkSearch(bestWord1, bestWord2)
Includes -best
checkIncludes(bestWord1, bestWord2)
Map - random
checkMap(randomWord1, randomWord1)
Search- random
checkSearch(randomWord1, randomWord1)
Includes- random
checkIncludes(randomWord1, randomWord1)
Map -bad
checkMap(badWord1, badWord2)
Search-bad
checkSearch(badWord1, badWord2)
Includes -bad
checkIncludes(badWord1, badWord2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (9)
Previous results
Fork
Test case name
Result
Map- best
Search- best
Includes -best
Map - random
Search- random
Includes- random
Map -bad
Search-bad
Includes -bad
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript benchmark test case created on the MeasureThat.net platform. The benchmark measures the performance of different approaches for substring-related operations in JavaScript. **Test Cases and Approaches** There are six test cases: 1. `checkMap(bestWord1, bestWord2)`: Tests the "map" approach, which uses a Map data structure to check if two strings contain common characters. 2. `checkSearch(bestWord1, bestWord2)`: Tests the "search" approach, which uses the `indexOf()` method to search for a substring in another string. 3. `checkIncludes(bestWord1, bestWord2)`: Tests the "includes" approach, which uses the `includes()` method to check if one string contains another substring. 4. `checkMap(randomString1, randomString2)`: Similar to test case 1, but with random strings instead of the "bestWord" strings. 5. `checkSearch(randomString1, randomString2)`: Similar to test case 2, but with random strings instead of the "bestWord" strings. 6. `checkIncludes(bestWord1, bestWord2)` and `checkIncludes(randomString1, randomString2)`: These test cases are similar to tests 3 and 4, but use a different approach (inclusion checking). **Approach Performance** The benchmark results show the performance of each approach on a Windows desktop device with Chrome 86 browser. The results are measured in executions per second. * `checkMap(bestWord1, bestWord2)`: Approximately 133-136 executions per second * `checkSearch(bestWord1, bestWord2)`: Approximately 125-130 executions per second * `checkIncludes(bestWord1, bestWord2)`: Approximately 131-134 executions per second * `checkMap(randomString1, randomString2)`: Approximately 50-55 executions per second (slower than the "bestWord" version) * `checkSearch(randomString1, randomString2)`: Approximately 60-65 executions per second (faster than the "bestWord" version) * `checkIncludes(bestWord1, bestWord2)` and `checkIncludes(randomString1, randomString2)`: Similar performance to test 3 **Conclusion** The benchmark results suggest that: * The "map" approach is generally the fastest for substring-related operations. * The "search" approach is slower than the "map" approach but faster than the "includes" approach when using strings with a large number of unique characters. * Randomized strings can introduce significant performance variations, making it harder to predict the best approach for your specific use case. Note: These results are based on a single browser and platform configuration. The actual performance may vary depending on other factors such as JavaScript engine, hardware, and software environments.
Related benchmarks:
WordsToNumbers2
Random ID generate
regex vs loop for word count
Object.create(null) vs {} vs Map() key access (heavy)
Comments
Confirm delete:
Do you really want to delete benchmark?