效率高的Javscript字符串替换函数的benchmark
时间:2024-04-22 12:47:39
可以任意转载,但转载时必须标明原作者charlee、原始链接http://tech.idv2.com/2006/11/23/javascript-strreplace-benchmark/以及本声明
我对这两个函数作了benchmark,发现新函数的效率约为原函数的1.4倍。虽然没有预想中那么高效率,但当要替换的字符串更多时,效率应该会提高吧。
测试方法为,对一个2048字节长的字符串分别执行两个函数100次,取其执行时间。下面为10次测试的结果。toTXT_1 为通常的作法,toTXT_2 为Clear的方法。
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% |
测试程序在这里http://img.aspxhome.com/online/javascript-benchmark/benchmark.htm
标签:Javscript,字符串替换函数,benchmark
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pygame与OpenCV联合播放视频并保证音画同步
2021-09-04 22:23:11
![](https://img.aspxhome.com/file/2023/6/127686_0s.jpg)
分享一个简单的python读写文件脚本
2022-11-21 20:03:00
Python实现图像尺寸和格式转换处理的示例详解
2021-02-17 06:33:10
Dephi逆向工具Dede导出函数名MAP导入到IDA中的实现方法
2023-04-09 06:31:40
![](https://img.aspxhome.com/file/2023/8/124358_0s.png)
MySQL学习之事务与并发控制
2024-01-27 22:36:39
![](https://img.aspxhome.com/file/2023/3/102363_0s.png)
php下intval()和(int)转换使用与区别
2023-06-11 14:09:54
Django 如何使用日期时间选择器规范用户的时间输入示例代码详解
2023-06-18 23:56:20
![](https://img.aspxhome.com/file/2023/1/64321_0s.gif)
Python用yield from实现异步协程爬虫的实践
2023-10-23 13:30:46
![](https://img.aspxhome.com/file/2023/4/115154_0s.png)
Python的numpy库中将矩阵转换为列表等函数的方法
2021-06-19 12:18:21
Python简单实现网页内容抓取功能示例
2023-01-09 00:32:30
Python加pyGame实现的简单拼图游戏实例
2021-12-20 04:31:45
用Python识别人脸,人种等各种信息
2023-12-22 08:22:17
![](https://img.aspxhome.com/file/2023/9/72889_0s.jpg)
JavaScript中常见的几种获取元素的方式
2023-07-13 07:46:12
![](https://img.aspxhome.com/file/2023/7/55937_0s.jpg)
导入tensorflow:ImportError: libcublas.so.9.0 报错
2023-07-07 11:44:46
![](https://img.aspxhome.com/file/2023/7/68257_0s.jpg)
python创建关联数组(字典)的方法
2021-11-22 06:51:18
高效管理http连接的方法
2022-02-16 23:12:14
![](https://img.aspxhome.com/file/2023/5/132505_0s.png)
如何用python抓取B站数据
2023-07-19 20:02:55
![](https://img.aspxhome.com/file/2023/7/60737_0s.jpg)
Python3视频转字符动画的实例代码
2022-02-09 12:29:29
Java 数据库连接池Druid 的介绍
2024-01-14 10:47:42
![](https://img.aspxhome.com/file/2023/2/96812_0s.png)
Python之Selenium自动化浏览器测试详解
2022-08-19 00:04:55
![](https://img.aspxhome.com/file/2023/2/131102_0s.png)