can javascript get tenths of a second

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guy

    can javascript get tenths of a second

    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=javasc ript>

    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.f 1.i5.value='Tes ting...';
    gettime();
    a=s;
    self.document.f 1.i1.value=h + ":" + m + ":" + s;
    self.document.f 1.i2.value='';
    if(n==0){n=1;se lf.document.pic .src='e1.gif';}
    else{n=0;self.d ocument.pic.src ='e2.gif';}
    }
    function calc()
    {
    gettime();
    b=s;
    self.document.f 1.i2.value=h + ":" + m + ":" + s;
    if((b-a)<0){b=b+60;}
    c=(b-a);
    if(c<2)
    {
    d="";
    e="";
    self.document.f 1.i5.value='You must delete your temporary Internet
    Files';
    }
    else
    {
    d=Math.round(15 994310/(c*1024))/10;
    e=Math.round(15 994310/c)/10;
    self.document.f 1.i5.value='Don e!';
    }
    self.document.f 1.i3.value=d;
    self.document.f 1.i4.value=e;
    }
    </SCRIPT>
    </HEAD>

    <BODY>
    <CENTER>


    <FORM name=f1>
    <TABLE border=1><TR><T D 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.b egin();'>
    <BR><BR>
    <INPUT name='i5' value='' size=50>
    <IMG name='pic' width=0 height=0 border=0 src='' onload='self.ca lc();'>
    </TD></TR></TABLE>
    </FORM>

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



  • Lee

    #2
    Re: can javascript get tenths of a second

    Guy said:[color=blue]
    >
    >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.[/color]

    var beginTime=new Date();
    doSomething();
    var endTime=new Date();
    ver difference=endT ime.getTime()-beginTime.getTi me();

    difference will be in thousands of a second.

    Comment

    • bagbourne

      #3
      Re: can javascript get tenths of a second

      Guy wrote:
      [color=blue]
      > 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=javasc ript>
      >
      > 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.f 1.i5.value='Tes ting...';
      > gettime();
      > a=s;
      > self.document.f 1.i1.value=h + ":" + m + ":" + s;
      > self.document.f 1.i2.value='';
      > if(n==0){n=1;se lf.document.pic .src='e1.gif';}
      > else{n=0;self.d ocument.pic.src ='e2.gif';}
      > }
      > function calc()
      > {
      > gettime();
      > b=s;
      > self.document.f 1.i2.value=h + ":" + m + ":" + s;
      > if((b-a)<0){b=b+60;}
      > c=(b-a);
      > if(c<2)
      > {
      > d="";
      > e="";
      > self.document.f 1.i5.value='You must delete your temporary Internet
      > Files';
      > }
      > else
      > {
      > d=Math.round(15 994310/(c*1024))/10;
      > e=Math.round(15 994310/c)/10;
      > self.document.f 1.i5.value='Don e!';
      > }
      > self.document.f 1.i3.value=d;
      > self.document.f 1.i4.value=e;
      > }
      > </SCRIPT>
      > </HEAD>
      >
      > <BODY>
      > <CENTER>
      >
      >
      > <FORM name=f1>
      > <TABLE border=1><TR><T D 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.b egin();'>
      > <BR><BR>
      > <INPUT name='i5' value='' size=50>
      > <IMG name='pic' width=0 height=0 border=0 src='' onload='self.ca lc();'>
      > </TD></TR></TABLE>
      > </FORM>
      >
      > </CENTER>
      > </BODY>
      > </HTML>[/color]

      Look in the manual for Date:



      You can get milliseconds.

      Comment

      • Dr John Stockton

        #4
        Re: can javascript get tenths of a second

        JRS: In article <brflob026k3@dr n.newsguy.com>, seen in
        news:comp.lang. javascript, Lee <REM0VElbspamtr ap@cox.net> posted at Sat,
        13 Dec 2003 10:28:27 :-[color=blue]
        >Guy said:[color=green]
        >>
        >>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.[/color]
        >
        >var beginTime=new Date();
        >doSomething( );
        >var endTime=new Date();
        >ver difference=endT ime.getTime()-beginTime.getTi me();
        >
        >difference will be in thousands of a second.[/color]

        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.demo n.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.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.

        Comment

        • Lee

          #5
          Re: can javascript get tenths of a second

          Dr John Stockton said:[color=blue]
          >
          >JRS: In article <brflob026k3@dr n.newsguy.com>, seen in
          >news:comp.lang .javascript, Lee <REM0VElbspamtr ap@cox.net> posted at Sat,
          >13 Dec 2003 10:28:27 :-[color=green]
          >>Guy said:[color=darkred]
          >>>
          >>>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.[/color]
          >>
          >>var beginTime=new Date();
          >>doSomething() ;
          >>var endTime=new Date();
          >>ver difference=endT ime.getTime()-beginTime.getTi me();
          >>
          >>difference will be in thousands of a second.[/color]
          >
          >Not really. Well, it will be an integer number of thousandths, but it
          >is not likely to have a resolution of one of those.[/color]

          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.

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: can javascript get tenths of a second

            bagbourne wrote:
            [color=blue]
            > [1 attribution line]
            > [1 blank line]
            > [131 lines of fullquote]
            > [1 blank line]
            > [6 lines of new text][/color]

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

            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.n et/pubs/munging-harmful/> for details.


            PointedEars

            Comment

            • Lee

              #7
              Re: can javascript get tenths of a second

              Thomas 'PointedEars' Lahn said:
              [color=blue]
              >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.n et/pubs/munging-harmful/> for details.[/color]

              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 "functional ity" 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.

              Comment

              • Guy

                #8
                Re: can javascript get tenths of a second... spam?

                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" <PointedEars@we b.de> wrote in message
                news:3FDCC9B6.6 050808@PointedE ars.de...[color=blue]
                > bagbourne wrote:
                >[color=green]
                > > [1 attribution line]
                > > [1 blank line]
                > > [131 lines of fullquote]
                > > [1 blank line]
                > > [6 lines of new text][/color]
                >
                > You may want to trim your quotes next time:
                > <http://www.netmeister. org/news/learn2quote2.ht ml>
                >
                > 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.n et/pubs/munging-harmful/> for details.
                >
                >
                > PointedEars[/color]


                Comment

                • Jeff Thies

                  #9
                  Re: can javascript get tenths of a second

                  > >By using a faked e-mail address you prevent yourself from getting[color=blue][color=green]
                  > >spam, but at the same time you help to destroy the Internet.[/color][/color]

                  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, and you have
                  to take some steps to avoid that. I really don't know what the best approach
                  is although it probably isn't mine!

                  Cheers,
                  Jeff
                  [color=blue]
                  >[/color]


                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: can javascript get tenths of a second

                    Jeff Thies wrote:
                    [color=blue][color=green][color=darkred]
                    >> >By using a faked e-mail address you prevent yourself from getting
                    >> >spam, but at the same time you help to destroy the Internet.[/color][/color]
                    >
                    > 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,[/color]

                    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.
                    [color=blue]
                    > and you have to take some steps to avoid that.[/color]

                    Definitely, see above.
                    [color=blue]
                    > I really don't know what the best approach is[/color]

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

                    Well, consider yourself killfiled then. Null problemo.


                    PointedEars

                    Comment

                    • HikksNotAtHome

                      #11
                      Re: can javascript get tenths of a second

                      In article <brv5mj$7kboh$1 @ID-107532.news.uni-berlin.de>, Thomas 'PointedEars'
                      Lahn <PointedEars@we b.de> writes:
                      [color=blue]
                      >Jeff Thies wrote:
                      >[color=green][color=darkred]
                      >>> >By using a faked e-mail address you prevent yourself from getting
                      >>> >spam, but at the same time you help to destroy the Internet.[/color]
                      >>
                      >> 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,[/color]
                      >
                      >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.[/color]

                      So, because I get spam mail from Newsgroups, I should manage it on my end? One
                      method of managing it is <gasp> not giving out a correct email address. Imagine
                      that.
                      [color=blue][color=green]
                      >> and you have to take some steps to avoid that.[/color]
                      >
                      >Definitely, see above.
                      >[color=green]
                      >> I really don't know what the best approach is[/color]
                      >
                      >Maybe using filters? Maybe complaining to the ISPs by mail so that *they*
                      >stop spammers, by removing their accounts and by closing open relays?[/color]

                      And one potential filter is to not give out the address. Mine is not munged,
                      but its because I don't care. I don't recieve internet email (compliments of
                      AOL mail filters) so its a non-issue to me.

                      But anybody that continuously complains about email addresses, attribute lines
                      and signatures has more time on there hands than they need.
                      [color=blue][color=green]
                      >> although it probably isn't mine![/color]
                      >
                      >Well, consider yourself killfiled then. Null problemo.[/color]

                      Can I join him? There are a few here that I wonder if they have killfiled me,
                      but rest assured you are not one of them.

                      P.S. Can you *please* explain how using a fake email address "helps destroy the
                      internet"? The internet was *not* developed as a mail system. Far from it.
                      --
                      Randy

                      Comment

                      • Dr John Stockton

                        #12
                        Re: can javascript get tenths of a second

                        JRS: In article <xkDEb.754$IM3. 343@newsread3.n ews.atl.earthli nk.net>,
                        seen in news:comp.lang. javascript, Jeff Thies <nospam@nospam. net> posted
                        at Fri, 19 Dec 2003 13:48:13 :-[color=blue][color=green][color=darkred]
                        >> >By using a faked e-mail address you prevent yourself from getting
                        >> >spam, but at the same time you help to destroy the Internet.[/color][/color]
                        >
                        >I used to believe that. That was the advice of many elders in the ciwa*
                        >(particularl y html) groups.Then my spam load hit 300+/day. At that point I
                        >no longer cared if the internet functioned because I couldn't.[/color]

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

                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
                        Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
                        Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
                        No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                        Comment

                        • Lee

                          #13
                          Re: can javascript get tenths of a second

                          Thomas 'PointedEars' Lahn said:
                          [color=blue]
                          >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.[/color]

                          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.


                          [color=blue]
                          >Maybe using filters? Maybe complaining to the ISPs by mail so that *they*
                          >stop spammers, by removing their accounts and by closing open relays?[/color]

                          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?

                          Comment

                          • AmateurScripter

                            #14
                            Re: can javascript get tenths of a second

                            "Guy" <someone@somewh ere.nb.ca> wrote in message news:<WtICb.108 93$IF6.504968@u rsa-nb00s0.nbnet.nb .ca>...[color=blue]
                            > 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=javasc ript>
                            >
                            > 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.f 1.i5.value='Tes ting...';
                            > gettime();
                            > a=s;
                            > self.document.f 1.i1.value=h + ":" + m + ":" + s;
                            > self.document.f 1.i2.value='';
                            > if(n==0){n=1;se lf.document.pic .src='e1.gif';}
                            > else{n=0;self.d ocument.pic.src ='e2.gif';}
                            > }
                            > function calc()
                            > {
                            > gettime();
                            > b=s;
                            > self.document.f 1.i2.value=h + ":" + m + ":" + s;
                            > if((b-a)<0){b=b+60;}
                            > c=(b-a);
                            > if(c<2)
                            > {
                            > d="";
                            > e="";
                            > self.document.f 1.i5.value='You must delete your temporary Internet
                            > Files';
                            > }
                            > else
                            > {
                            > d=Math.round(15 994310/(c*1024))/10;
                            > e=Math.round(15 994310/c)/10;
                            > self.document.f 1.i5.value='Don e!';
                            > }
                            > self.document.f 1.i3.value=d;
                            > self.document.f 1.i4.value=e;
                            > }
                            > </SCRIPT>
                            > </HEAD>
                            >
                            > <BODY>
                            > <CENTER>
                            >
                            >
                            > <FORM name=f1>
                            > <TABLE border=1><TR><T D 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.b egin();'>
                            > <BR><BR>
                            > <INPUT name='i5' value='' size=50>
                            > <IMG name='pic' width=0 height=0 border=0 src='' onload='self.ca lc();'>
                            > </TD></TR></TABLE>
                            > </FORM>
                            >
                            > </CENTER>
                            > </BODY>
                            > </HTML>[/color]


                            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.

                            Comment

                            Working...