Shop OBEX P1 Docs P2 Docs Learn Events
calculating program segment execution speed? — Parallax Forums

calculating program segment execution speed?

JedJed Posts: 107
edited 2008-02-19 00:15 in BASIC Stamp
Is there a list of how many clock cycles each PBASIC command ends up taking? I'm trying to calculate the time it will take for a specific segment of code to execute. I know I can probably figure it out by trial and error but it would be nice if I could just calculate it somehow. Possible?

Comments

  • ZootZoot Posts: 2,227
    edited 2008-02-19 00:15
    Because the Stamp uses an interpreter, and raw compiled code, it's hard to think of (or calculate) times in terms of clock cycles or "instructions" -- Pbasic statements are not instructions per se.

    That said, if you are looking for some pretty good estimates on actual times for setting up and executing some common Pbasic commands, see Dr. Tracy Allen's notes on the subject here: emesystems.com/BS2speed.htm

    I will also add as a matter of programming style, that while you can not achieve true time regularity like you could with an SX or the like, it does help to keep times more consistent by using structures that *always* evaluate in some fashion -- rather than IF/THEN and similar statements. Example:

    ioByte = ioByte MIN 1 - 1 ' this always take approx. same amount of time to execute
    
    IF ioByte > 0 THEN          ' this takes different amount of time depending on how ioByte > 0 evaluates
       ioByte = ioByte - 1       ' additionally you will find this actually takes a LOT more code space than you would think
    ENDIF                             ' compared to the above
    
    ' here's another one:
    
    dur = dur + 1
    LOOKUP dur.BIT1 ^ ioByte.BIT0, [noparse][[/noparse] ioByte, ioByte + 1 MAX $F ], ioByte
    
    ' equals:
    
    dur = dur + 1
    IF dur.BIT1 <> ioByte.BIT0 AND ioByte < $F THEN
        ioByte = ioByte + 1
    ENDIF
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.