Speed of time/processor

Discussion in 'Computer Science & Culture' started by Fuse26, Oct 28, 2011.

Thread Status:
Not open for further replies.
  1. Fuse26 011 Banned

    Messages:
    54
    Does this program measure time or the processing speed (or both?) It was inspired by reading how processors can operate a number of calculations, but I was wondering what this value is. As it transpires the value changes from second to second. The for...next loop then matches the speed (this can be done for the previous second also by inserting 'e=c' after the second loop and rewriting d to count to e):

    Code:
    1
    
    a$=time$
    b$=time$
    
    while (b$=a$)
    
    b$=time$
    
    wend
    
    a$=time$
    b$=time$
    
    c=0
    
    while (b$=a$)
    
    b$=time$
    
    c=c+1
    
    for d=0 to c
    
    next d
    
    wend
    
    goto 1
    
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Chipz Banned Banned

    Messages:
    838
    The answer is no. Indent your code properly and I will tell you why.
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. river-wind Valued Senior Member

    Messages:
    2,671
    I think it won't give you much useful information about processor cycle timing because first off I don't think it would compile.

    Next, I don't think it would do *anything*, assuming that time$ is supposed to be the machine's clock. Setting a$ then b$ would result in two distinct values, and as such neither while loop will ever be executed.

    Also, you have a goto in there, and thus I must now set you on fire. That is the law of programming, and we follow the law here.
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. Pincho Paxton Banned Banned

    Messages:
    2,387
    With current processor speeds, I doubt that the number will change, I don't think computers have the accuracy for it to change. So the speed correction will not work.
     
  8. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,104
    Script languages are iterated by an "Interpreter", which means the script can operate at a cycle speed as opposed to actual processor speed. If you truly wanted to look towards closer ties to processing speed, you'd be better looking at either direct assembly programming or the application of how a script can be "Compiled" and how that functions at the assembly level.

    Something else to mull over...

    555
     
    Last edited: Oct 29, 2011
  9. Fuse26 011 Banned

    Messages:
    54
    The program does work! I've tried it on QBasic and YABASIC on the playstation (I have a demo that came free with the playstation.)

    I can't if I'm posting code. When I did that it removed the spacing so I had to return and line up the lines so they matched.

    Please Register or Log in to view the hidden image!



    Oh the program works.
    The loops are executed because b$ changes each loop. Please re-check the code.
    I agree.

    Please Register or Log in to view the hidden image!



    Thanks for all your replies. I have done some reading and what I found was quite interesting:

    Frequency: i.e. how OFTEN something occurs...

    ...however the data my program has produced does not appear to match: it is far from a SMOOTH oscillation; in fact the data appears to be random, so much so that it is suitable for most gameplay; dice rolls etc.

    Please Register or Log in to view the hidden image!

     
  10. river-wind Valued Senior Member

    Messages:
    2,671

    Please Register or Log in to view the hidden image!

    I had no idea someone ported qbasic to more modern hardware. you're running this on the PS1? In what environment, some debugging console, or a PC based emulator? (I haven't done Playstation development).
    The lines I was referring to come before the loop actually starts.:
    Code:
    a$=time$
    b$=time$
    
    while (b$=a$)
    A$ will be set to time$, which I would expect to be something like 1236421832. Then B4 gets set to time$, which I'd expect to be something like 1236421833. Therefore the initial while check "while (b$=a$)' would fail.

    Since it seems to be not failing, is time$ only measured down to a single second or some other large measurement?
     
  11. Fuse26 011 Banned

    Messages:
    54
    Actually on the playstation. It's called YABASIC (Yet Another BASIC) and it comes free with a demo disc with the playstation one.
    Yeah time is only measured in seconds. The yabasic time shows hh:mm:ss:xx

    (xx=time program has been running)
     
  12. river-wind Valued Senior Member

    Messages:
    2,671
    That is awesome! Do you plug in a keyboard directly to the playstation and type in the code directly?

    Ah! I see a possible issue that might crop up occasionally - when the second changes in between your two assignment calls to time$. It might be better to set A$ equal to time$, and then set B$ equal to A$ prior to initiating to loop; that will ensure you don't have a start condition where A$!=B$. I'd expect this would only be an issue very rarely, like once out of 1000 times you ran the program.

    edit:
    Code:
    1
      a$=time$
      b$=time$
      while (b$=a$)
        b$=time$
      wend
      a$=time$
      b$=time$
      c=0
      while (b$=a$)
        b$=time$
        c=c+1
        for d=0 to c
        next d
      wend
    goto 1
    Test case: Time$=1:00:00
    a$ and b$ are set to 1:00:00, while loop runs, re-setting b$ until a$=1:00:00 and b$=1:00:01. a$ and b$ are then both set to time$ again, which now equals 1:00:01. c$ is set to 0, while loop two begins. b$ is set to time$, c is incremented to 1, and the for loop does from d=0 to 1. The while loop goes through round 2, b is set to time$ (still 1:00:01), c is incrimented to 2, and the for loop runs from 0 to 2. This continues until time$ changes to 1:00:02.

    There is no output, though if you are tracing the values of a$, b$, c$, and d$, you can see the change. Why are a$ and b$ specified with '$', but c and d are not? If you are watching the values change in real time, what is the purpose of the for loop? to slow down the execution of the while loop? Is the increasing delay in the completion of the while loop attempting to act in concert with the increasing value for time$ in some fashion?
     
    Last edited: Nov 10, 2011
  13. Aqueous Id flat Earth skeptic Valued Senior Member

    Messages:
    6,152
    this little ditty:

    a$=time$
    while a$=time$
    wend

    is a low precision one second delay.

    the counter [c] gets incremented while it's waiting for the 1 second delay to time out.
    this gives you fresh updates once a second

    the second loop (d=0 to c:next) is a gradually increasing delay as [c] gets closer and closer to overflow. Since it slows gradually, it allows the program to adjust to machines that are fast or slow.

    another thing you can do is keep a running average of the processor speed is it starts jumping around. for example, before you clear c, put it into the average:
    :
    x=(x+c)/2
    c=0
    :

    set x=0 way at the top of the program.
    there are different ways to average, this one slows down the jumpiness while still letting you know things are changing.

    also note, your program can be used to test how other programs hog the CPU by launching, then closing various apps while your program is "measuring" the CPU.
     
  14. Chipz Banned Banned

    Messages:
    838
    These things I have to assume are blatantly untrue. Spin-locking won't do what you're asking for, and it has serious repercussions. Spin-locking indefinitely is just insane.
     
Thread Status:
Not open for further replies.

Share This Page