Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Comparison between replace and split map join with Map
(version: 0)
Comparing performance of:
split map join vs split map join Map vs loop Map vs loop
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const defaultSubs = { '1': 'i', '0': 'o', '5': 's', '9': 'g', '6': 'b', '7': 't', // eslint-disable-line '3': 'e', '+': 't', '$': 's', '^': 'n', '|': 'i', 'А': 'a', // eslint-disable-line 'Б': 'b', 'В': 'b', 'Г': 'r', 'Ґ': 'r', 'Д': 'a', 'Ђ': 'h', // eslint-disable-line 'Ѓ': 'r', 'Е': 'e', 'Ё': 'e', 'Є': 'c', 'ç': 'c', 'û': 'u', // eslint-disable-line 'Ж': 'x', 'З': 'e', 'З́': 'e', 'Ѕ': 's', 'И': 'n', 'І': 'i', // eslint-disable-line 'Ї': 'i', 'Й': 'n', 'Ј': 'j', 'К': 'k', 'Л': 'n', 'Љ': 'b', // eslint-disable-line 'М': 'm', 'Н': 'h', 'Њ': 'h', 'О': 'o', 'Р': 'p', 'С': 'c', // eslint-disable-line 'С́': 'c', 'Т': 't', 'Ћ': 'h', 'Ќ': 'k', 'У': 'y', 'Ў': 'y', // eslint-disable-line 'Ф': 'o', 'Х': 'x', 'Ц': 'u', 'Ч': 'y', 'Џ': 'u', 'Ш': 'w', // eslint-disable-line 'Щ': 'w', 'Ъ': 'b', 'Ы': 'bl','Ь': 'b', 'Э': 'e', 'Ю': 'io', // eslint-disable-line 'Я': 'r', 'Ӏ': 'i', 'Ә': 'b', 'Ғ': 'r', 'Ҙ': 'e', 'Ҫ': 'c', // eslint-disable-line 'Ҡ': 'k', 'Җ': 'x', 'Қ': 'k', 'Ң': 'h', 'Ҥ': 'h', 'Ө': 'o', // eslint-disable-line 'Ү': 'y', 'Ұ': 'y', 'Һ': 'h', 'Ҳ': 'x', 'Α': 'a', 'α': 'a', // eslint-disable-line 'Β': 'b', 'β': 'b', 'Γ': 'r', 'γ': 'y', 'Δ': 'a', 'δ': 'o', // eslint-disable-line 'Ε': 'e', 'ε': 'e', 'Ο': 'o', 'ο': 'o', 'Π': 'n', 'π': 'n', // eslint-disable-line 'Ρ': 'p', 'ρ': 'p', 'Σ': 'e', 'σ': 'o', 'ς': 'c', 'Τ': 't', // eslint-disable-line 'τ': 't', 'Υ': 'y', 'υ': 'u', 'Φ': 'o', 'φ': 'o', 'Χ': 'x', // eslint-disable-line 'χ': 'x', 'Ψ': 'w', 'ψ': 'w', 'Ω': 'o', 'ω': 'w', '@': 'a', // eslint-disable-line '4': 'a' }; const defaultSubs2 = new Map(JSON.parse('[["0","o"],["1","i"],["3","e"],["4","a"],["5","s"],["6","b"],["7","t"],["9","g"],["+","t"],["$","s"],["^","n"],["|","i"],["А","a"],["Б","b"],["В","b"],["Г","r"],["Ґ","r"],["Д","a"],["Ђ","h"],["Ѓ","r"],["Е","e"],["Ё","e"],["Є","c"],["ç","c"],["û","u"],["Ж","x"],["З","e"],["З́","e"],["Ѕ","s"],["И","n"],["І","i"],["Ї","i"],["Й","n"],["Ј","j"],["К","k"],["Л","n"],["Љ","b"],["М","m"],["Н","h"],["Њ","h"],["О","o"],["Р","p"],["С","c"],["С́","c"],["Т","t"],["Ћ","h"],["Ќ","k"],["У","y"],["Ў","y"],["Ф","o"],["Х","x"],["Ц","u"],["Ч","y"],["Џ","u"],["Ш","w"],["Щ","w"],["Ъ","b"],["Ы","bl"],["Ь","b"],["Э","e"],["Ю","io"],["Я","r"],["Ӏ","i"],["Ә","b"],["Ғ","r"],["Ҙ","e"],["Ҫ","c"],["Ҡ","k"],["Җ","x"],["Қ","k"],["Ң","h"],["Ҥ","h"],["Ө","o"],["Ү","y"],["Ұ","y"],["Һ","h"],["Ҳ","x"],["Α","a"],["α","a"],["Β","b"],["β","b"],["Γ","r"],["γ","y"],["Δ","a"],["δ","o"],["Ε","e"],["ε","e"],["Ο","o"],["ο","o"],["Π","n"],["π","n"],["Ρ","p"],["ρ","p"],["Σ","e"],["σ","o"],["ς","c"],["Τ","t"],["τ","t"],["Υ","y"],["υ","u"],["Φ","o"],["φ","o"],["Χ","x"],["χ","x"],["Ψ","w"],["ψ","w"],["Ω","o"],["ω","w"],["@","a"]]')) function replace1(str) { const keys = Object.keys(defaultSubs); let content = str for (let i = 0; i < keys.length; i += 1) { content = str.replace(keys[i], defaultSubs[keys[i]]); } return content } function replace2(str) { return str.split('').map(x => defaultSubs[x] !== undefined ? defaultSubs[x] : x).join('') } function replace3(str) { return str.split('').map(x => defaultSubs2.get(x) !== undefined ? defaultSubs2.get(x) : x).join('') } function replace4(str) { let content = str for (const keya of defaultSubs2.keys()) { content = str.replace(keya, defaultSubs2.get(keya)); } return content }
Tests:
split map join
replace2('@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994')
split map join Map
replace3('@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994')
loop Map
replace4('@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994')
loop
replace1('@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994@n1m4710n n199@ 61994')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
split map join
split map join Map
loop Map
loop
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):
Based on the provided benchmark results, I'll provide an analysis of the performance differences between the different test cases. **Overview** The benchmark results show the execution rate per second for each test case across multiple browsers and devices. The tests seem to be comparing different approaches to string manipulation, such as looping, mapping, and using regular expressions (regex). **Key Findings** 1. **Loop vs. Loop Map**: The "loop" test case consistently performs better than the "loop map" test case, with a 4-6x speedup across all devices. This suggests that loop iteration is more efficient for this specific use case. 2. **Split Map Join**: The "split map join" test cases have similar performance profiles, with no significant differences between the two implementations (Map and non-Map). However, the "split map join Map" test case performs slightly better than the "split map join" test case on some devices. 3. **Regular Expression Replacement**: The test cases involving regex replacement ("replace1", "replace2", "replace3", and "replace4") exhibit varying performance patterns across browsers and devices. **Insights** * Loop iteration seems to be more efficient for this specific use case, which involves iterating over a string and replacing substrings. * The split map join operation is relatively stable across different implementations (Map and non-Map), but the loop-based implementation remains faster on some devices. * Regular expression replacement can introduce performance variability depending on the browser, device, and regex pattern complexity. **Recommendations** Based on these findings, I recommend: 1. Use loop iteration for string manipulation tasks that involve iterating over a string and replacing substrings. 2. Optimize regular expression replacement patterns to minimize computational overhead. 3. Consider using more efficient data structures or algorithms for large-scale string processing workloads. Please note that these recommendations are based on the provided benchmark results and may not be universally applicable. Further testing and optimization may be necessary to achieve optimal performance in specific use cases.
Related benchmarks:
Comparison between replace and split map join
Comparison between replace and split map join test2
Comparison between replace and split map join with Map 222
Diacritics removal (+ lowercase2)
Comments
Confirm delete:
Do you really want to delete benchmark?