Benchmark_javascript techniques for efficient javscript string substitution functions

Source: Internet
Author: User
Tags benchmark
Can be reproduced arbitrarily, but the reprint must be marked original author Charlee, the original link http://tech.idv2.com/2006/11/23/javascript-strreplace-benchmark/and this statement

I benchmark these two functions and found that the efficiency of the new functions is about 1.4 times times that of the original function. While not as efficient as expected, the efficiency should be increased when more strings are being replaced.

The test method is to perform two functions 100 times for a 2048-byte long string, taking its execution time. The following is the result of 10 tests. Totxt_1 for the usual practice, totxt_2 as clear method.

Totxt_1 (MS) Totxt_2 (MS) Totxt_1/totxt_2
1609 160° 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%

The test program is here http://img.jb51.net/online/javascript-benchmark/benchmark.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.