var Watch = {
    result: [],
    guid: -1,
    totalTime: 0,
    start: function(title){
        this.result[++this.guid] = [title || this.guid, new Date().getTime()];
    },
    stop: function(){
        var r = this.result[this.guid];
        var t = new Date().getTime() - r[1];
        this.totalTime += t;
        r[1] = t;
    },
    report: function(){
        this.guid = -1;
        var div = document.createElement("div");
        div.style.fontSize = "12px";
        document.body.appendChild(div);
        var str = [];
        str.push("<p><b>The total times:</b><span style='color:#f00'>" + this.totalTime + "</span> ms.</p>");
        for (var i = 0, l = this.result.length; i < l; i++) {
            if (this.result[i].length > 1) {
                var temp = document.createElement("div");
                var span = document.createElement("span");
                var inner_span = document.createElement("span");
                
                temp.appendChild(span);
                span.appendChild(inner_span);
                
                span.style.width = "200px";
                span.style.display = "inline-block";
                span.style.backgroundColor = "#eee";
                
                inner_span.style.backgroundColor = "#f00";
                inner_span.style.width = parseInt(200 * this.result[i][1] / this.totalTime) + "px";
                inner_span.style.display = "inline-block";
                inner_span.innerHTML = this.result[i][1];
                
                str.push("<p><span style='width:150px; display:inline-block;'>" + this.result[i][0] + ":</span>  " + temp.innerHTML + "</p>");
                
                temp = null;
                span = null;
                inner_span = null;
            }else{
				str.push(this.result[i][0]);
			}
        }
        div.innerHTML = str.join("");
    },
    fns: function(){
        var a = arguments;
        for (var i = 0, l = a.length; i < l; i++) {
            this.start(a[i][0]);
            a[i][1]();
            this.stop();
        }
    },
    execByTimes: function(fn, times, title){
        this.start(title);
        while (times--) {
            fn();
        }
        this.stop();
    },
    print: function(str){
        this.result[++this.guid]=[str];
    }
}

