[翻译]High Performance JavaScript(017)
A Note on Benchmarking 测试基准说明
Because a regex's performance can be wildly different depending on the text it's applied to, there's no straightforward way to benchmark regexes against each other. For the best result, you need to benchmark your regexes on test strings of varying lengths that match, don't match, and nearly match.
因为正则表达式性能因应用文本不同而产生很大差异,没有简单明了的方法可以测试正则表达式之间的性能差别。为得到最好的结果,你需要在各种字符串上测试你的正则表达式,包括不同长度,能够匹配的,不能匹配的,和近似匹配的。
That's one reason for this chapter's lengthy backtracking coverage. Without a firm understanding of backtracking, you won't be able to anticipate and identify backtracking-related problems. To help you catch runaway backtracking early, always test your regexes with long strings that contain partial matches. Think about the kinds of strings that your regexes will nearly but not quite match, and include those in your tests.
这也是本章长篇大论回溯的原因之一。如果没有确切理解回溯,就无法预测和确定回溯相关问题。为帮助你早日把握回溯失控,总是用包含特殊匹配的长字符串测试你的正则表达式。针对你的正则表达式构思一些近似但不能完全匹配的字符串,将他们应用在你的测试中。
More Ways to Improve Regular Expression Efficiency 提高正则表达式效率的更多方法
The following are a variety of additional regex efficiency techniques. Several of the points here have already been touched upon during the backtracking discussion.
下面是一写提高正则表达式效率的技术。几个技术点已经在回溯部分讨论过了。
Focus on failing faster
关注如何让匹配更快失败
Slow regex processing is usually caused by slow failure rather than slow matching. This is compounded by the fact that if you're using a regex to match small parts of a large string, the regex will fail at many more positions than it will succeed. A change that makes a r
相关文档:
页面提交数据一般有两种方法:get,post。post就是所谓的form提交,使用视图;get是通过url提交。
Get方法一般用后台代码(如asp,asp.net)获得参数,代码很简单:Request.QueryString["id"];即可获取。
有些时候需要直接在前台获取url参数,要用到javascript,js没有直接获取url参数的方法,那么,我们如何通过js ......
<script>
//写cookies函数 作者:翟振凯
function
SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值
{
var Days = 30;
//此 cookie 将被保存 30 天
var exp = new Date(); //new
Date("December 31, 9998");
  ......
玩PHP、Delphi、Java基本上都有对象,习惯这种思路后上手任何语言都想靠OO思路,这绝不是在赶时髦,而是把相关代码进行内聚的确可以体会到维护的方便!
在JavaScript中如何创建对象?
JavaScript是基于对象的!它也是以Object为根类,其它类继承之。在根类提供了几个方法。供继承类使用!
以下是创建对象的例子:
funct ......
Regular Expression Optimization 正则表达式优化
Incautiously crafted regexes can be a major performance bottleneck (the upcoming section, "Runaway Backtracking" on page 91, contains several examples showing how severe this can be), but there is a lot you can do to improve re ......