JAVASCRIPT完全自学手册,中源码的验证修订实例
源代码在线查看: 9-6 正则编译的效果.htm
9-6 正则编译的效果
* { font-size:12px; font-family:宋体, Arial; } /*规定了所有的字体样式*/
function init(){
var str, regObj, t01, t02, startTime;
str = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPp";
startTime = new Date();
regObj = /kLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCc/g;
for(var i=0; i str.match(regObj);
}
t01 = (new Date()) - startTime;
regObj = regObj.compile("kLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpAaBbCc", "g");
startTime = new Date();
for(var i=0; i str.match(regObj);
}
t02 = (new Date()) - startTime;
alert("循环执行50000遍,\r\n未编译的正则耗时 "+t01+"毫秒,\r\n已编译的正则耗时"+t02+"毫秒");
}
window.onload = init;