Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
replaceAll vs regex replace pt4
(version: 0)
Benchmark.js
Comparing performance of:
replace regex vs replace All vs split & join
Created:
2 years ago
by:
Guest
Go to the latest result
Tests:
replace regex
"Lorem\x7Fipsum\x7Fdolor\x7Fsit\x7Famet,\x7Fconsectetur\x7Fadipiscing\x7Felit,\x7Fsed\x7Fdo\x7Feiusmod\x7Ftempor\x7Fincididunt\x7Fut\x7Flabore\x7Fet\x7Fdolore\x7Fmagna\x7Faliqua.\x7FUt\x7Fenim\x7Fad\x7Fminim\x7Fveniam,\x7Fquis\x7Fnostrud\x7Fexercitation\x7Fullamco\x7Flaboris\x7Fnisi\x7Fut\x7Faliquip\x7Fex\x7Fea\x7Fcommodo\x7Fconsequat.\x7FDuis\x7Faute\x7Firure\x7Fdolor\x7Fin\x7Freprehenderit\x7Fin\x7Fvoluptate\x7Fvelit\x7Fesse\x7Fcillum\x7Fdolore\x7Feu\x7Ffugiat\x7Fnulla\x7Fpariatur.\x7FExcepteur\x7Fsint\x7Foccaecat\x7Fcupidatat\x7Fnon\x7Fproident,\x7Fsunt\x7Fin\x7Fculpa\x7Fqui\x7Fofficia\x7Fdeserunt\x7Fmollit\x7Fanim\x7Fid\x7Fest\x7Flaborum.".replace(/\x7F/g, "+");
replace All
"Lorem\x7Fipsum\x7Fdolor\x7Fsit\x7Famet,\x7Fconsectetur\x7Fadipiscing\x7Felit,\x7Fsed\x7Fdo\x7Feiusmod\x7Ftempor\x7Fincididunt\x7Fut\x7Flabore\x7Fet\x7Fdolore\x7Fmagna\x7Faliqua.\x7FUt\x7Fenim\x7Fad\x7Fminim\x7Fveniam,\x7Fquis\x7Fnostrud\x7Fexercitation\x7Fullamco\x7Flaboris\x7Fnisi\x7Fut\x7Faliquip\x7Fex\x7Fea\x7Fcommodo\x7Fconsequat.\x7FDuis\x7Faute\x7Firure\x7Fdolor\x7Fin\x7Freprehenderit\x7Fin\x7Fvoluptate\x7Fvelit\x7Fesse\x7Fcillum\x7Fdolore\x7Feu\x7Ffugiat\x7Fnulla\x7Fpariatur.\x7FExcepteur\x7Fsint\x7Foccaecat\x7Fcupidatat\x7Fnon\x7Fproident,\x7Fsunt\x7Fin\x7Fculpa\x7Fqui\x7Fofficia\x7Fdeserunt\x7Fmollit\x7Fanim\x7Fid\x7Fest\x7Flaborum.".replaceAll("\x7F", "+");
split & join
"Lorem\x7Fipsum\x7Fdolor\x7Fsit\x7Famet,\x7Fconsectetur\x7Fadipiscing\x7Felit,\x7Fsed\x7Fdo\x7Feiusmod\x7Ftempor\x7Fincididunt\x7Fut\x7Flabore\x7Fet\x7Fdolore\x7Fmagna\x7Faliqua.\x7FUt\x7Fenim\x7Fad\x7Fminim\x7Fveniam,\x7Fquis\x7Fnostrud\x7Fexercitation\x7Fullamco\x7Flaboris\x7Fnisi\x7Fut\x7Faliquip\x7Fex\x7Fea\x7Fcommodo\x7Fconsequat.\x7FDuis\x7Faute\x7Firure\x7Fdolor\x7Fin\x7Freprehenderit\x7Fin\x7Fvoluptate\x7Fvelit\x7Fesse\x7Fcillum\x7Fdolore\x7Feu\x7Ffugiat\x7Fnulla\x7Fpariatur.\x7FExcepteur\x7Fsint\x7Foccaecat\x7Fcupidatat\x7Fnon\x7Fproident,\x7Fsunt\x7Fin\x7Fculpa\x7Fqui\x7Fofficia\x7Fdeserunt\x7Fmollit\x7Fanim\x7Fid\x7Fest\x7Flaborum.".split("\x7F").join("+");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
replace regex
replace All
split & join
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
replace regex
503.0M/s
split & join
762K/s
replace All
528K/s
View exact numbers
Test name
Executions per second
✓
replace regex
503,038,784 Ops/sec
split & join
762,075 Ops/sec
replace All
528,156 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript benchmarks! The provided JSON data represents a benchmarking framework, specifically MeasureThat.net, which allows users to create and run JavaScript microbenchmarks. **Benchmark Definition** The benchmark definition is a string that contains the code snippet to be executed. In this case, there are three different definitions: 1. `"Lorem\\x7Fipsum\\x7Fdolor\\x7Fsit\\x7Famet,...".replace(/\\x7F/g, "+");` (Test Name: "replace regex") 2. `"Lorem\\x7Fipsum\\x7Fdolor\\x7Fsit\\x7Famet,...".replaceAll("\\x7F", "+");` (Test Name: "replace All") 3. `"Lorem\\x7Fipsum\\x7Fdolor\\x7Fsit\\x7Famet,...".split("\\x7F").join("+");` (Test Name: "split & join") **Benchmark Results** The latest benchmark results are available, showing the performance of each test across different executions per second. The results are as follows: 1. "replace regex" - 503,038,784 executions/second 2. "split & join" - 762,074.75 executions/second 3. "replace All" - 528,156.375 executions/second **Comparison** The benchmark results suggest that the order of operations (i.e., replacement and splitting) has a significant impact on performance. The `replaceAll` method appears to be the fastest, followed by `split & join`, and then `replace regex`. In general, the replacement method is faster because it uses a single operation, whereas the other two methods involve multiple steps: splitting the string into an array, joining the elements back together, and then performing the replacement. Keep in mind that these results are specific to this benchmark test and may not be representative of all scenarios. Additionally, the performance differences between these methods can vary depending on factors such as the size and complexity of the input strings.
Related benchmarks
replaceAll vs regex replace (no prep code)
Comments
Confirm delete:
Do you really want to delete benchmark?