This statement can be reproduced at will, but the original author charlee and original link http://tech.idv2.com/2006/11/23/javascript-strreplace-benchmark/must be specified during reprinting.
I made a benchmark on these two functions and found that the efficiency of the new functions is about 1.4 times that of the original functions. Although it is not as efficient as expected, the efficiency should be improved when there are more strings to be replaced.
The test method is to execute two functions 2048 times for a 100-byte string, and obtain the execution time. The following are the results of 10 tests. Totxt_1 is the common practice, and totxt_2 is the clear method.
Totxt_1 (MS) |
Totxt_2 (MS) |
Totxt_1/totxt_2 |
1609 |
1204 |
75% |
2250 |
1547 |
69% |
1672 |
1313 |
79% |
1813 |
1250 |
69% |
1844 |
1219 |
66% |
2063 |
1421 |
69% |
2031 |
1172 |
58% |
1797 |
1360 |
76% |
2015 |
1281 |
64% |
1860 |
1500 |
81% |
TestProgramHere http://img.jb51.net/online/javascript-benchmark/benchmark.htm