Elapsed time

D

duane.barlow

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
 
D

duane.barlow

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()?
 
T

Thomas 'PointedEars' Lahn

duane.barlow said:
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
 
J

jhurstus

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).
 
D

Dr J R Stockton

In comp.lang.javascript message <ce95a30a-3a6f-48b2-a956-86f02d614201@q3
9g2000hsf.googlegroups.com>, Wed, 9 Jan 2008 14:59:55, duane.barlow
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.
 
E

Evertjan.

Dr J R Stockton wrote on 10 jan 2008 in comp.lang.javascript:
There should be no problem with that subtraction.

Except when passing local midnight during the measurement.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
Dr J R Stockton wrote on 10 jan 2008 in comp.lang.javascript:


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top