Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Detecting processor speed in QBasic?

Dr. COM WIZDr. COM WIZ Posts: 74Member
Hello, world. This is Dr. COM WIZ incase you couldn't guess (Okay, I stole that from Pink, the singer. I won't use it anymore, alright?). I am currently working on a Qbaic game that is all about speed. It works very well on the computer that Mom and Dad bought recently. After all, this is the computer I made the game in. However, for some reason, I wanted to use my older computer. I guess it's because I wanted to bring back the old Windows for Work Groups 3.1's memories. I tested my games in the [100% pure] DOS 6.22, but it wasn't the same as it was with 333 MHz Windows 98 with the fake DOS that I use. My game ran much, much more slowly and some what out of order. I honeslty don't think don't think it's because of the different versions of DOS. I think it's because my old computer is slower (DUH!):-o! When my game comes out, it won't make it big unless it works well for all PCs woth DOS.

Main Problem: If anyone knows how to detect the CPUs speed before gameplay, please teach me or atleast tell me.

This has been,
Dr. COM WIZ

PS What's the differnce between Windows 3.1, Windows 3.0, and Windows for Work Groups 3.1? Thank you and goodnight!


Comments

  • deldel Posts: 51Member
    I'm not sure how to detect the CPU's exact speed in MHz, but you could test how long the computer takes to perform a certain operation to give an indication as to how fast it is. For example:
    [code]
    StartTime = TIMER
    FOR TestCpu& = 1 TO 500000: NEXT TestCpu&
    CpuSpeed = TIMER - StartTime
    PRINT CpuSpeed
    [/code]
    In the example above, the program will print out how long it took to do half a million loops. The [italic]lower[/italic] the value of CpuSpeed is, the faster the computer.

    The problem with this method is that on very old computers, it could take a couple of seconds to perform this test, and the user may think their computer has frozen. So instead of testing time per number of loops, you can test number of loops per time unit:
    [code]
    StartTime = TIMER
    CpuSpeed& = 0
    PRINT "Testing...";
    DO
    CpuSpeed& = CpuSpeed& + 1
    LOOP UNTIL TIMER => StartTime + .3
    PRINT "done." + CHR$(13) + CpuSpeed&
    [/code]
    This will test how many loops the machine is able to do in 0.3 seconds. Unlike the previous example, this test will take the same amount of time (0.3 seconds) no matter what the speed of the machine. The [italic]higher[/italic] the value of CpuSpeed&, the faster the computer.

    Neither of these are very accurate - you will notice variations in the results if you run the programs a couple of times, but they will give an indication.

  • Dr. COM WIZDr. COM WIZ Posts: 74Member
    : I'm not sure how to detect the CPU's exact speed in MHz, but you could test how long the computer takes to perform a certain operation to give an indication as to how fast it is. For example:
    : [code]
    : StartTime = TIMER
    : FOR TestCpu& = 1 TO 500000: NEXT TestCpu&
    : CpuSpeed = TIMER - StartTime
    : PRINT CpuSpeed
    : [/code]
    : In the example above, the program will print out how long it took to do half a million loops. The [italic]lower[/italic] the value of CpuSpeed is, the faster the computer.
    :
    : The problem with this method is that on very old computers, it could take a couple of seconds to perform this test, and the user may think their computer has frozen. So instead of testing time per number of loops, you can test number of loops per time unit:
    : [code]
    : StartTime = TIMER
    : CpuSpeed& = 0
    : PRINT "Testing...";
    : DO
    : CpuSpeed& = CpuSpeed& + 1
    : LOOP UNTIL TIMER => StartTime + .3
    : PRINT "done." + CHR$(13) + CpuSpeed&
    : [/code]
    : This will test how many loops the machine is able to do in 0.3 seconds. Unlike the previous example, this test will take the same amount of time (0.3 seconds) no matter what the speed of the machine. The [italic]higher[/italic] the value of CpuSpeed&, the faster the computer.
    :
    : Neither of these are very accurate - you will notice variations in the results if you run the programs a couple of times, but they will give an indication.
    : Thank you, but I really like the second recipe better. I can test it on my old computer and new to find the right speed for my game.

    --Dr. COM WIZ


Sign In or Register to comment.