Announcement

Collapse
No announcement yet.

Read Computer's speed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read Computer's speed

    Is there some way to read a computer's speed and so adjust the speed with which a PowerBASIC program runs? I developed a PowerBASIC program years ago on a slow Hz computer then when I upgraded my computer to a faster Hz, I had to build in delays in order to see what was on the screen.

  • #2
    Not really... But there are a couple of ways that you could handle it.

    You could add a "test loop" to the very beginning of your program, and use it to calibrate the rest of your loops. In other words, if the test loop runs in 5 seconds on your old computer and 1 second on your new computer (as measured with TIMER or MTIMER) then you would set a "multiplier" variable to 5 to tell all of your delay loops how long to run. The rest of your delay loops would look like this...

    Code:
    FOR X% = 1 TO (DelayCount * Multiplier)
       'WHATEVER
    NEXT
    But if you do that, remember that Windows will fool you. If you're running your PB/DOS program on a Windows computer 1) Windows will give more "attention" to your program for the first couple of seconds after your program starts, so the rest of your program will not run at the same speed, and 2) the speed of any program on a Windows computer is dependent on how many other programs are running at the same time, and how CPU-intensive they are. So your program is very likely to speed up and slow down, more or less randomly.

    A much better way to "moderate" the speed of your program would be to use TIMER- or DELAY-based delays instead of loop-based delays. That way, your program would delay for a certain number of seconds or milliseconds, instead of delaying for the time it takes to execute a loop a certain number of times, because DELAY is not (very) machine-speed dependent. The resolution of DELAY/TIMER is limited to about 0.05 milliseconds, so it averages 50% of that accuarcy or about 0.1 seconds. In other words, if you write a function and tell it to delay 0.05 seconds, you will actually get a delay between 0.0 and 0.1 seconds, with an average delay of 0.05. The longer the delay, the more accurate (percentage-wise) it will be.

    If your program runs on Windows computers the "ultimate" solution would be to convert it to the PowerBASIC PB/CC compiler. The Windows SLEEP function has a resolution of about 10 milliseconds (0.01 seconds), and even more accurate timing functions are available.

    HTH.

    -- Eric

    ADDED LATER: I just re-read your message and I'm not really sure how I got the idea that you were using loop-based delays. Oh well, the info might be useful anyway...

    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:s[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited March 17, 2000).]
    "Not my circus, not my monkeys."

    Comment


    • #3
      There are a number of delay routines in the ABC Archives.
      http://www.basicguru.com/abc

      Do a search on topics:TIMERS, DELAYS, SPEED and see what you get.

      ------------------
      Walt Decker

      Comment


      • #4
        Karl --

        > Does this hold true if you boot-up in MSDOS mode?

        Which part are you asking about?

        If you're asking about Windows "fooling you", then No. If you boot into the MS-DOS mode, Windows is virtually 100% out of the picture, so as far as I know apps will run at a constant speed (ignoring disk/network access delays, etc.). And PB/CC console applications can't be run in that mode... they require that Windows be running.

        -- Eric

        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>



        [This message has been edited by Eric Pearson (edited March 18, 2000).]
        "Not my circus, not my monkeys."

        Comment


        • #5
          All
          I think we have missed the point I raised, namely, is there some way to read the computer's speed. I would like to include it in the program so the program will make the appropriate adjustment.
          I am in the process of developing programs that I hope to market and I will need to have them run on various speed computers.
          Fred

          ------------------

          Comment


          • #6
            Ummm... I did? I think you mean Eric.
            Lance
            mailto:[email protected]

            Comment


            • #7
              Fred --

              > I think we have missed the point I raised, namely,
              > is there some way to read the computer's speed.

              Actually, I think you missed the answer. The answer is No. PCs do not provide any sort of hook, interrupt, API, or anything else that returns the processor speed. Even if they did, it would be meaningless on Windows computers for the reasons that I outlined.

              I stand by my previous response: "Not really... But there are a couple of ways that you could handle it."

              -- Eric


              ------------------
              Perfect Sync: Perfect Sync Development Tools
              Email: mailto:[email protected][email protected]</A>

              "Not my circus, not my monkeys."

              Comment


              • #8
                Eric
                Thanks, I had seen your answer before but just wondered if anyone else might know a way. But you latest answer is just more complete. Thanks again.
                Fred

                ------------------

                Comment


                • #9
                  Eric Pearson wrote
                  PCs do not provide any sort of hook, interrupt, API, or anything else that returns the processor speed

                  Maybe I'm missing the obvious, but... if that's the case, how is it that your BIOS can display your CPU speed on bootup?

                  ------------------

                  Comment


                  • #10
                    Heck if I know!

                    That "CPU Speed" string that you see on bootup is probably hard-coded into the chip's startup code for display puposes. But that doesn't mean that a hook/interrupt/API/etc. is provided to return that string (or the "speed" part of it) to a program. In other words, just because you can do this in a PB program...

                    Code:
                    PRINT "This is version 1.00 of my program"
                    ...that doesn't mean that the program was written to use that string in any other way. Or that the version number was somehow "measured" and reported by that line of code.

                    I honestly don't know the answer, but I'm 99.9999% certain that IBM-compatible computers do not provide a method for applications to obtain the "CPU Speed" number at runtime.

                    -- Eric

                    ------------------
                    Perfect Sync: Perfect Sync Development Tools
                    Email: mailto:[email protected][email protected]</A>

                    "Not my circus, not my monkeys."

                    Comment


                    • #11
                      Code:
                      Eric is right.  No CPU will report its own speed.  That's because the 
                      reliable speed of a CPU isn't known until it's tested after being 
                      manufactured.  If the 450Mhz chip performs reliably at 450 Mhz, it's 
                      stamped as such and priced accordingly.  If the same chip tests out 
                      at 400Mhz or 350Mhz, then it's sold as a 400Mhz or 350Mhz.
                         
                      Pentium-class and later CPUs will return their features through the 
                      CPUID function (the manufacturer's name, MMX or not, etc.), but never 
                      the processor's speed.  To determine speed, even the BIOS does what 
                      your program has to do: It tests the CPU itself.  This is why, if you 
                      set motherboard jumpers incorrectly, your 450Mhz PII will be reported 
                      as running at 200Mhz or some other speed--which will be correct.  The 
                      motherboard will be handling the CPU incorrectly, and the speed 
                      reported will tell you that's happening.  (Of course, if the jumpers 
                      are correct, then you'll know that your new CPU is probably 
                      remarked--a lower-speed chip remarked as higher speed by the crook 
                      who sold it).


                      ------------------
                      -- Greg
                      [email protected]

                      Comment


                      • #12
                        Dear Fred

                        have a look at the url http://members.xoom.com/B_coolWare/

                        you will find very reliable code in c and pascal for reading all cpu types and speed

                        also he provides com and exe programs whick can pie output to text file fro reading into dos

                        I have used this method for 3 years on over 700 pcs on most makes

                        hope this helps

                        ron hurley
                        [email protected]

                        ------------------

                        Comment

                        Working...
                        X