Javascript 字符串匹配与 for 循环
我有一个 extjs 网格,其中一个列渲染器函数有一个 for 循环,它遍历一组数字并将它们与所考虑的列的每个单元格的值进行比较。所以我在想,因为渲染器已经为每一行循环,现在我为每一行都有 for 循环运行器。
问题是应该让它运行,还是应该更改数组和用户 String.match() 而不是 for 循环。
我现在没有大数据,所以我可以测试。哪个更好?有什么想法吗?
谢谢, 贾伊
I have an extjs grid and one of the column renderer function has a for loop which goes through an array of numbers and compares them with the value for every cell for the column in consideration. so I was thinking since the renderer already loops for each row, and now i have for loop runner for each row.
The question is should just let it run or should i change the array and user String.match() instead of for loop.
I don't have large data for now so that i could test. Which is better? any ideas?.
Thanks,
Jai
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想对一段需要很短时间才能获得有用数字的代码进行基准测试,则可以在循环内多次运行它。
在 JavaScript 中,您可以轻松获得执行一段代码所需的时间(以毫秒为单位),如下所示:
每当您询问有关特定代码段的问题时,您应该随问题一起提供代码,这确实很难计算根据您的描述,您的代码做了什么。
If you want to benchmark a piece of code that takes too little time to get useful numbers, then run it multiple times inside a loop.
In JavaScript you can easily get the time (in milliseconds) it takes to execute a piece of code like this:
Whenever you ask a question about a specific piece of code you should provide the code along with the question, it is really hard to figure what your code does from your description.