原来是自己理解有误
参考:http://www.daimajiayuan.com/sitejs-12541-1.html
测试工具:
http://www.w3school.com.cn/tiy/t.asp?f= ... te_gettime
代码不论循环多少次输出的时差都是0
甚至循环到运行了十几秒钟也是输出0
测试代码:
代码: 全选
<html>
<body>
<script type="text/javascript">
// Generated by gfwlist2pac
// https://github.com/clowwindy/gfwlist2pac
var proxy = "PROXY 127.0.0.1:80";
var domains = {
'googleusercontent.com':0,
'twitter.com':0,
'googleapis.com':0,
'google.com.hk':0,
'blogblog.com':0
};
var direct = 'DIRECT';
var hasOwnProperty = Object.hasOwnProperty;
function FindProxyForURL(url, host) {
var suffix;
var pos = host.lastIndexOf('.');
pos = host.lastIndexOf('.', pos - 1);
while(1) {
if (pos <= 0) {
if (hasOwnProperty.call(domains, host)) {
return proxy;
} else {
return direct;
}
}
suffix = host.substring(pos + 1);
if (hasOwnProperty.call(domains, suffix)) {
return proxy;
}
pos = host.lastIndexOf('.', pos - 1);
}
}
var d=new Date();
start_t=d.getTime();
for(var i=0;i<1000000;i++)
FindProxyForURL('https://www.google.com/','www.google.com');
end_t=d.getTime();
document.write(end_t-start_t);
</script>
</body>
</html>