jQuery选择器的性能测试(4)
return this.ltLastTime = new Date().getTime();
}
var diff = new Date().getTime() - this.ltLastTime;
this.ltLastTime = null;
$.l(diff);
return diff;
},
ltLastTime: null
});
/**
* Shortcut function for benchmarking a block of code to the Firebug console
* this function will run your code in a for block to create overflow and push the results into Firebug
*
* @param string benchmarkCode - the block of code you want to benchmark
* @param numeric testTime - the number of FOR cicles
*/
$.extend($, {
bm: function (benchmarkCode, testTime) {
this.testTime = typeof testTime === 'number' ? testTime : 9999;
$.lt();
for (var i = 0;i < this.testTime;i++) {
eval(benchmarkCode);
}
$.lt();
}
});
/**
* Mock ajax requests with a prefilter
*
*/
$.extend($, {
mockAjax: function (mockOptions) {
mockOptions = $.extend({
mockUrl: '/ajax_mocks'
}, mockOptions);
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
if (!options.noMock) {
options.url = mockOptions.mockUrl + '?ajax_url=' + encodeURIComponent(options.url);
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>