开发者

Javascript String Match Vs for loop

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜