can javascript get tenths of a second

G

Guy

I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.

Thanks for all,
Guy

My current HTML document looks like this:
The calculation is based on the size of the file I was using.


<HTML>
<HEAD>
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Cache-Control" Content="max-age=0">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">

<SCRIPT language=javascript>

var a;
var b;
var c;
var d;
var e;
var h;
var m;
var s;
var n;

n=0;

function gettime()
{
var t = new Date();
h = t.getHours();
m = t.getMinutes();
s = t.getSeconds();
}
function begin()
{
self.document.f1.i5.value='Testing...';
gettime();
a=s;
self.document.f1.i1.value=h + ":" + m + ":" + s;
self.document.f1.i2.value='';
if(n==0){n=1;self.document.pic.src='e1.gif';}
else{n=0;self.document.pic.src='e2.gif';}
}
function calc()
{
gettime();
b=s;
self.document.f1.i2.value=h + ":" + m + ":" + s;
if((b-a)<0){b=b+60;}
c=(b-a);
if(c<2)
{
d="";
e="";
self.document.f1.i5.value='You must delete your temporary Internet
Files';
}
else
{
d=Math.round(15994310/(c*1024))/10;
e=Math.round(15994310/c)/10;
self.document.f1.i5.value='Done!';
}
self.document.f1.i3.value=d;
self.document.f1.i4.value=e;
}
</SCRIPT>
</HEAD>

<BODY>
<CENTER>


<FORM name=f1>
<TABLE border=1><TR><TD align=center>
<BR>
<FONT SIZE=4>Trial Speed-Test site</FONT><BR><BR>
<TABLE cellspacing=0 cellpadding=2 border=0>
<TR><TD>Start time </TD><TD><INPUT name='i1' value=''>
</TD></TR>
<TR><TD>End Time </TD><TD><INPUT name='i2' value=''>
</TD></TR>
<TR><TD>Speed </TD><TD><INPUT name='i3' value=''> kilobytes per second
</TD></TR>
<TR><TD> </TD><TD><INPUT name='i4' value=''> Bytes per second
</TD></TR>
</TABLE>
<BR>
<IMG name='test' width=100 height=100 border=1 src='test.gif'
onclick='self.begin();'>
<BR><BR>
<INPUT name='i5' value='' size=50>
<IMG name='pic' width=0 height=0 border=0 src='' onload='self.calc();'>
</TD></TR></TABLE>
</FORM>

</CENTER>
</BODY>
</HTML>
 
L

Lee

Guy said:
I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.

var beginTime=new Date();
doSomething();
var endTime=new Date();
ver difference=endTime.getTime()-beginTime.getTime();

difference will be in thousands of a second.
 
B

bagbourne

Guy said:
I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.

Thanks for all,
Guy

My current HTML document looks like this:
The calculation is based on the size of the file I was using.


<HTML>
<HEAD>
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Cache-Control" Content="max-age=0">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">

<SCRIPT language=javascript>

var a;
var b;
var c;
var d;
var e;
var h;
var m;
var s;
var n;

n=0;

function gettime()
{
var t = new Date();
h = t.getHours();
m = t.getMinutes();
s = t.getSeconds();
}
function begin()
{
self.document.f1.i5.value='Testing...';
gettime();
a=s;
self.document.f1.i1.value=h + ":" + m + ":" + s;
self.document.f1.i2.value='';
if(n==0){n=1;self.document.pic.src='e1.gif';}
else{n=0;self.document.pic.src='e2.gif';}
}
function calc()
{
gettime();
b=s;
self.document.f1.i2.value=h + ":" + m + ":" + s;
if((b-a)<0){b=b+60;}
c=(b-a);
if(c<2)
{
d="";
e="";
self.document.f1.i5.value='You must delete your temporary Internet
Files';
}
else
{
d=Math.round(15994310/(c*1024))/10;
e=Math.round(15994310/c)/10;
self.document.f1.i5.value='Done!';
}
self.document.f1.i3.value=d;
self.document.f1.i4.value=e;
}
</SCRIPT>
</HEAD>

<BODY>
<CENTER>


<FORM name=f1>
<TABLE border=1><TR><TD align=center>
<BR>
<FONT SIZE=4>Trial Speed-Test site</FONT><BR><BR>
<TABLE cellspacing=0 cellpadding=2 border=0>
<TR><TD>Start time </TD><TD><INPUT name='i1' value=''>
</TD></TR>
<TR><TD>End Time </TD><TD><INPUT name='i2' value=''>
</TD></TR>
<TR><TD>Speed </TD><TD><INPUT name='i3' value=''> kilobytes per second
</TD></TR>
<TR><TD> </TD><TD><INPUT name='i4' value=''> Bytes per second
</TD></TR>
</TABLE>
<BR>
<IMG name='test' width=100 height=100 border=1 src='test.gif'
onclick='self.begin();'>
<BR><BR>
<INPUT name='i5' value='' size=50>
<IMG name='pic' width=0 height=0 border=0 src='' onload='self.calc();'>
</TD></TR></TABLE>
</FORM>

</CENTER>
</BODY>
</HTML>

Look in the manual for Date:

http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/date.html#1193137

You can get milliseconds.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
Guy said:

var beginTime=new Date();
doSomething();
var endTime=new Date();
ver difference=endTime.getTime()-beginTime.getTime();

difference will be in thousands of a second.

Not really. Well, it will be an integer number of thousandths, but it
is not likely to have a resolution of one of those.

AIUI, in DOS..Win98, resolution is about 55 ms; in WinNT+ it is 10 ms.

However, it may depend on browser, on OS, and even on CPU. RSVP. To
test your system, execute the following with the Eval button in
<URL:http://www.merlyn.demon.co.uk/js-quick.htm> or otherwise.

var J, T, XT=0, XXT

J = 0 ; XXT = T = new Date().getTime()

while (J <= 10) {
if (T != XT) { XT = T ; J++ }
T = new Date().getTime() }

"On your system, it measures at about " +
(new Date() - XXT)/10 + " ms less possible overheads."


Mr bagbourne should read the FAQ; to learn about trimming quotes, and to
learn some facts about javascript.
 
L

Lee

Dr John Stockton said:
JRS: In article <[email protected]>, seen in


Not really. Well, it will be an integer number of thousandths, but it
is not likely to have a resolution of one of those.

Yes, really. The difference will be in thousands of a second.
It will not be accurate to 1 thousandth of a second, but that
is the unit that is reported.
 
T

Thomas 'PointedEars' Lahn

bagbourne said:
[1 attribution line]
[1 blank line]
[131 lines of fullquote]
[1 blank line]
[6 lines of new text]

You may want to trim your quotes next time:
<http://www.netmeister.org/news/learn2quote2.html>

Besides:

| [20:15:51] pointedears:~ $ host -t mx noway.com
| Server: 193.189.244.205
| Address: 193.189.244.205#53
|
| ** server can't find noway.com: SERVFAIL

By using a faked e-mail address you prevent yourself from getting
spam, but at the same time you help to destroy the Internet. Due
to the egotistical behavior you display with such, I will not
download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.


PointedEars
 
L

Lee

Thomas 'PointedEars' Lahn said:
By using a faked e-mail address you prevent yourself from getting
spam, but at the same time you help to destroy the Internet. Due
to the egotistical behavior you display with such, I will not
download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.

How do you suppose these rank in terms of harming the usefulness
of the Internet:
1) Using a false email address
2) Spam
3) Constantly nagging people who use false addresses

I would put using a false address last, personally.
The "functionality" that is lost is not an important feature.
I first stopped using an email address that I actually read
when I started getting too much personal email from people in
newsgroups, not because of spam.
 
G

Guy

Ok, from your postings, I assume your not a spam artist looking to add my
email to a spam list! :)

But from what I understand, newsgroups are desinged for people to share on
the newsgroup and not by email. I wouldn't expect someone to mail me an
answer, nor would I email someone an answer. For one thing, it's possible
that my answer may be wrong and by posting it, people can correct me.

And I'm definitely not going to hand over my email address to spammers. The
Internet is being slowed down enough by junk mail, including messages asking
you to email as many friends as you know to get money from microsoft and
AOL, and then I get about 20 emails from people I thought were smart! So
actually, I think that by not including my email address I am doing the
opposite of destroying the Internet.

But since you asked, does anyone know of a safe way to give out your email
address in a posting without any spammers picking it up?

Trying to do the right thing,

Guy


Thomas 'PointedEars' Lahn said:
bagbourne said:
[1 attribution line]
[1 blank line]
[131 lines of fullquote]
[1 blank line]
[6 lines of new text]

You may want to trim your quotes next time:
<http://www.netmeister.org/news/learn2quote2.html>

Besides:

| [20:15:51] pointedears:~ $ host -t mx noway.com
| Server: 193.189.244.205
| Address: 193.189.244.205#53
|
| ** server can't find noway.com: SERVFAIL

By using a faked e-mail address you prevent yourself from getting
spam, but at the same time you help to destroy the Internet. Due
to the egotistical behavior you display with such, I will not
download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Jeff said:
I used to believe that. That was the advice of many elders in the ciwa*
(particularly html) groups.Then my spam load hit 300+/day. At that point I
no longer cared if the internet functioned because I couldn't.

Usenet denizens are particularly badly hit by SPAM harvesters,

Undoubtedly. I get many spam mails -- but the most of it is filtered
server-side before I need to download it or it blocks my mailbox. The
rest (about 10 per day) is filtered client-side by Mozilla's Junk Mail Controls.
and you have to take some steps to avoid that.

Definitely, see above.
I really don't know what the best approach is

Maybe using filters? Maybe complaining to the ISPs by mail so that *they*
stop spammers, by removing their accounts and by closing open relays?
although it probably isn't mine!

Well, consider yourself killfiled then. Null problemo.


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>,
seen in news:comp.lang.javascript said:
I used to believe that. That was the advice of many elders in the ciwa*
(particularly html) groups.Then my spam load hit 300+/day. At that point I
no longer cared if the internet functioned because I couldn't.

Ignore Thomas Lahn; he's a twerp, who thinks he understands what is
going on.. He'll have kill-filed everybody before long.
 
L

Lee

Thomas 'PointedEars' Lahn said:
Undoubtedly. I get many spam mails -- but the most of it is filtered
server-side before I need to download it or it blocks my mailbox. The
rest (about 10 per day) is filtered client-side by Mozilla's Junk Mail Controls.

If you're filtering out all spam, then you're almost certainly
also filtering out some legitmate email. That's a price that
I'm not eager to pay.


Maybe using filters? Maybe complaining to the ISPs by mail so that *they*
stop spammers, by removing their accounts and by closing open relays?

So I should spend additional time sending email to ISP's, in
hopes that I can motivate them to stop taking somebody's money,
because they have offended me?
 
A

AmateurScripter

Guy said:
I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.

Thanks for all,
Guy

My current HTML document looks like this:
The calculation is based on the size of the file I was using.


<HTML>
<HEAD>
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Cache-Control" Content="max-age=0">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">

<SCRIPT language=javascript>

var a;
var b;
var c;
var d;
var e;
var h;
var m;
var s;
var n;

n=0;

function gettime()
{
var t = new Date();
h = t.getHours();
m = t.getMinutes();
s = t.getSeconds();
}
function begin()
{
self.document.f1.i5.value='Testing...';
gettime();
a=s;
self.document.f1.i1.value=h + ":" + m + ":" + s;
self.document.f1.i2.value='';
if(n==0){n=1;self.document.pic.src='e1.gif';}
else{n=0;self.document.pic.src='e2.gif';}
}
function calc()
{
gettime();
b=s;
self.document.f1.i2.value=h + ":" + m + ":" + s;
if((b-a)<0){b=b+60;}
c=(b-a);
if(c<2)
{
d="";
e="";
self.document.f1.i5.value='You must delete your temporary Internet
Files';
}
else
{
d=Math.round(15994310/(c*1024))/10;
e=Math.round(15994310/c)/10;
self.document.f1.i5.value='Done!';
}
self.document.f1.i3.value=d;
self.document.f1.i4.value=e;
}
</SCRIPT>
</HEAD>

<BODY>
<CENTER>


<FORM name=f1>
<TABLE border=1><TR><TD align=center>
<BR>
<FONT SIZE=4>Trial Speed-Test site</FONT><BR><BR>
<TABLE cellspacing=0 cellpadding=2 border=0>
<TR><TD>Start time </TD><TD><INPUT name='i1' value=''>
</TD></TR>
<TR><TD>End Time </TD><TD><INPUT name='i2' value=''>
</TD></TR>
<TR><TD>Speed </TD><TD><INPUT name='i3' value=''> kilobytes per second
</TD></TR>
<TR><TD> </TD><TD><INPUT name='i4' value=''> Bytes per second
</TD></TR>
</TABLE>
<BR>
<IMG name='test' width=100 height=100 border=1 src='test.gif'
onclick='self.begin();'>
<BR><BR>
<INPUT name='i5' value='' size=50>
<IMG name='pic' width=0 height=0 border=0 src='' onload='self.calc();'>
</TD></TR></TABLE>
</FORM>

</CENTER>
</BODY>
</HTML>


Ok. You can do some math to convert the milliseconds to tenths of a
second. You could use Math.floor and divide by 100. That would give
you tenths of a second.
 

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
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top