页面性能调优辅助脚本类

来源:互联网 发布:ise软件win8 编辑:程序博客网 时间:2024/06/05 16:16

由于部分页面对性能要求非常严格,ms级别,所以需要对页面加载、页面DOM元素初始化与展现做调试。附带写了个小TOOL。

希望对大家有所帮助。


function StringBuilder(value) { this.strings = new Array(""); this.append(value); }StringBuilder.prototype.append = function(value) { if (value) this.strings.push(value); }StringBuilder.prototype.clear = function() { this.strings.length = 1; }StringBuilder.prototype.toString = function() { return this.strings.join(""); }/* DOM耗时调试 *//*AddMsg("PageInit",new Date());Debuger = true;ShowStepMsg = false;ShowResult();*/var result = new StringBuilder();var time = new Date();var Debuger = false;var ShowStepMsg = false;function DateDiff(sDate1, sDate2) {//格式1900/01/01 01:01:01     //new Date(year,month-1,day,0,0,0,0);     var startDate = new Date(sDate1.replace("-", "/"));    var endDate = new Date(sDate2.replace("-", "/"));    return Math.abs(endDate - startDate) / 1000; //把相差的毫秒数转换为秒 }function GetCurrentDate() {    var now = new Date();    var currentDate = now.getYear();    currentDate += "-" + (now.getMonth() + 1);    currentDate += "-" + now.getDate();    currentDate += " " + now.getHours();    currentDate += ":" + now.getMinutes();    currentDate += ":" + now.getSeconds();    return currentDate;}Date.prototype.format = function(format) {    var o = {        "M+": this.getMonth() + 1, //month         "d+": this.getDate(), //day         "h+": this.getHours(), //hour         "m+": this.getMinutes(), //minute         "s+": this.getSeconds(), //second         "q+": Math.floor((this.getMonth() + 3) / 3), //quarter         "S": this.getMilliseconds() //millisecond     }    if (/(y+)/.test(format)) {        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));    }    for (var k in o)        if (new RegExp("(" + k + ")").test(format))        format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));    return format;}SetStepTime = function(date) {    return date.format('yyyy-MM-dd hh:mm:ss:S');}AddMsg = function(tip, date) {    if (Debuger) {        result.append(tip + "," + SetStepTime(date) + "\r\n");        if (ShowStepMsg) ShowResult();    }}ShowResult = function() {    alert(result.toString());}


原创粉丝点击