记录请求的往返加载时间

发布于 2024-11-25 03:24:37 字数 678 浏览 1 评论 0原文

我正在使用测试脚本来测量测试页面的往返时间。 我不需要测量的时间准确,我只是希望趋势稳定,这样我就可以看到高(呃)负载下加载时间的增加。

为此,我使用两种方法(在 JavaScript 中)来测量加载时间。

1:

var start_time = (new Date).getTime();
//load the resource
var end_time = (new Date).getTime() - start_time;

2:

var time_passed = 0;
var timer = setInterval("time_passed += 10;", 10);
//load the resource
clearInterval(timer);

我读到第一种方法的分辨率在大多数浏览器中都很低, 唯一给出“良好”结果的浏览器是 chrome,

第二种方法在浏览器中非常稳定,并给出恒定的结果。

正如预期的那样,测量的时间对于日期差异来说非常不规则,而对于间隔计时器来说则非常稳定。 然而,我的问题是,我删除了日期差计时器,因为它无法使用,一旦删除它,间隔测量就变得非常不稳定。测量的时间峰值低于和高于趋势。

任何人都可以解释为什么一旦日期差异被消除,间隔就不稳定。

和/或如何改进时机。

I am using a testscript to measure the round-trip times of a test page.
I dont need the measured time to be accurate, I just want the trend to be stable so i can see the increase in load times under high(er) load.

For this I use 2 methods (in javascript) to measure the loadtime.

1:

var start_time = (new Date).getTime();
//load the resource
var end_time = (new Date).getTime() - start_time;

2:

var time_passed = 0;
var timer = setInterval("time_passed += 10;", 10);
//load the resource
clearInterval(timer);

I have read that the resolution of the first method is low in most browsers,
the only browser who gives a "good" result is chrome

the second method is very stable across browsers and gives a constant result.

The measured times are, as was to be expected, very irregular for the date difference, and very stable for the interval timer.
My problem however is that i removed the date difference timer because it was unusable, once i removed it the interval measurements became very unstable. The measured times peak under and above the trend.

Can anyone explain why the interval is unstable once the date difference is removed.

And/or maby how to improve on the timing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2024-12-02 03:24:37

使用 javascript 来衡量其自身的执行速度被认为是相当不准确的。相反,我建议使用内置分析器(在 Safari 和 Chrome 中),它使您能够测量每个函数调用,而网络分析器可以为您提供准确的请求时间。

Using javascript to measure it's own execution speed is considered fairly inaccurate. Instead, I'd recommend using built-in profiler (in Safari and Chrome) which enables you to measure even every single function call and network profiler which gives you accurate request times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文