Javascript 字符串匹配与 for 循环

发布于 2024-09-28 12:55:54 字数 222 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百善笑为先 2024-10-05 12:55:54

如果您想对一段需要很短时间才能获得有用数字的代码进行基准测试,则可以在循环内多次运行它。

在 JavaScript 中,您可以轻松获得执行一段代码所需的时间(以毫秒为单位),如下所示:

var starttime= +new Date()
//Do the task
var endtime= +new Date()
alert(endtime-starttime)

每当您询问有关特定代码段的问题时,您应该随问题一起提供代码,这确实很难计算根据您的描述,您的代码做了什么。

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:

var starttime= +new Date()
//Do the task
var endtime= +new Date()
alert(endtime-starttime)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文