By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,728 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

Elapsed time

P: n/a
I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:

var start = new Date();

and then after the last javascript call I have:

var end = new Date();
var elapsedTimeInMilliseconds = end - start;
report(elapsedTimeInMilliseconds);

the report function sends the value back to the server.

This is working fine for me, but the report that is coming back from
the back-end containing all 500,000 or so hits to the page contains
some preposterously high numbers and also even some negative numbers.
Am I doing something wrong here? Can anyone think of a reason this
wouldn't be working, or how I could possibly get a negative value?

Thanks so much in advance!

-Duane
Jan 9 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
duane.barlow wrote:
I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:

var start = new Date();

and then after the last javascript call I have:

var end = new Date();
var elapsedTimeInMilliseconds = end - start;
You don't need `end':

var elapsedTimeInMilliseconds = new Date() - start;

For that matter, you don't need `elapsedTimeInMilliseconds' either.
report(elapsedTimeInMilliseconds);
report(new Date() - start);
the report function sends the value back to the server.

This is working fine for me, but the report that is coming back from
the back-end containing all 500,000 or so hits to the page contains
some preposterously high numbers and also even some negative numbers.
Am I doing something wrong here? Can anyone think of a reason this
wouldn't be working, or how I could possibly get a negative value?
You could get a negative value when your site happens to be loading between
a system clock modification on the client. That could be a general clock
correction, even an automated one using an NTP server. Looks like as if you
should log the timestamps as well.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jan 10 '08 #2

P: n/a
On Jan 9, 2:32 pm, "duane.barlow" <duane.bar...@gmail.comwrote:
I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:
If you're not already, I would suggest logging the user agent string
and IP address with these data. You might find a correlation between
a particular client configuration (or specific clients) and the bogus
values. Hopefully this extra info will elucidate the cause.

The negative values (if they're small) are probably due to an NTP
driven system clock change (as mentioned by Thomas).
Jan 10 '08 #3

P: n/a
jh******@gmail.com said the following on 1/10/2008 1:04 AM:
On Jan 9, 2:32 pm, "duane.barlow" <duane.bar...@gmail.comwrote:
>I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:

If you're not already, I would suggest logging the user agent string
and IP address with these data. You might find a correlation between
a particular client configuration (or specific clients) and the bogus
values. Hopefully this extra info will elucidate the cause.

The negative values (if they're small) are probably due to an NTP
driven system clock change (as mentioned by Thomas).
It took me a while to find that setting and realize that it was the
source of a lot of frustration for me doing timed items with the clock
set to auto-update itself.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '08 #4

P: n/a
In comp.lang.javascript message <ce95a30a-3a6f-48b2-a956-86f02d614201@q3
9g2000hsf.googlegroups.com>, Wed, 9 Jan 2008 14:59:55, duane.barlow
<du**********@gmail.composted:
>The strange thing is that almost all of the numbers make sense except
sometimes there is an enormous number of milliseconds that equates to
like 300 years.. It goes without saying that the page hadn't been
loading that long, but how could that number be getting reported? Is
it incorrect to subtract two date objects directly, should i be doing
end.getTime() - start.getTime()?
There should be no problem with that subtraction.

After digesting the newsgroup FAQ section 2.3, you should report the
exact number of milliseconds, and where known the OS and browser
combination in which it was seen.

300 years is usually 9467107200000 ms, otherwise 9467020800000 ms; about
9.5e12 ms.

You might have a server or analysis problem.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 10 '08 #5

P: n/a
Dr J R Stockton wrote on 10 jan 2008 in comp.lang.javascript:
>>it incorrect to subtract two date objects directly, should i be doing
end.getTime() - start.getTime()?

There should be no problem with that subtraction.
Except when passing local midnight during the measurement.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 11 '08 #6

P: n/a
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Fri, 11 Jan 2008 09:14:37, Evertjan. <ex**************@interxnl.net>
posted:
>Dr J R Stockton wrote on 10 jan 2008 in comp.lang.javascript:
>>>it incorrect to subtract two date objects directly, should i be doing
end.getTime() - start.getTime()?

There should be no problem with that subtraction.

Except when passing local midnight during the measurement.
There should be no problem with that subtraction.

x = [+new Date(), new Date().valueOf(), new Date().getTime()]

- 1200069319625,1200069319625,1200069319625 (in IE6; FF2 Op9 akin)

However. methods .getTimeOnly(), .getUTCTimeOnly() could be a useful
addition to the Date Object; also .getDateOnly(), .getUTCDateOnly().

I wonder whether the *original* intention was for .getTime() and
..valueOf() to differ !

CAVEAT : Safari 3.0.4 : it seems that a Date Object can be set to a
value above the lawful range. The code

D = new Date(864e5*(1e8-1)) ; D.setDate(22) ; X = D/864e5

gives 100000009 in Safari, but NaN in IE6 IE7 FF2 Op9. Reported.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jan 11 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.