Shop OBEX P1 Docs P2 Docs Learn Events
programming advice — Parallax Forums

programming advice

thegoat001thegoat001 Posts: 4
edited 2008-09-17 18:57 in BASIC Stamp
So I have about 1.5KB of code for my bs2sx and while I'm not really concerned about speed...I'm using two program slots, can anyone tell me if the bs2 would execute faster if I split the code 50/50 in slot 0 and 1? I'd imagine it takes time for the stamp to move from slot 0 to 1, but if not, would it be better to go ahead and use all 8 program slots and divide the code up equally? Currently I have 70% of the code in slot 0 and 30% in slot 1. It should be noted that the program runs all the way through slot 0 before running all the way through slot 1 and does not jump back and forth to specific parts of the code.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-09-17 08:12
    You should split the code as the logic dictates, not run speed. The purpose of the slots ( and methods for that matter) is to allow you to easily test and debug your code, and to keep it well maintained. As for time, somewhere it mentions (in the Reference and Syntax manual, maybe?) estimated transition times. If my memory serves me right, it's about 2x longer than the program execution speed (per instruction).
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-09-17 12:51
    No, the code would run slower if you made more "RUN" calls between the two code slots.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2008-09-17 15:30
    I had timed the RUN command on the BS2sx at 300 microseconds. (www.emesys.com/BS2speed.htm#timetables)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-09-17 17:06
    Except, once you've DONE the "RUN" command, you still have to "GOSUB" or "GOTO" the right place in your code to continue.

    Besides, isn't 300 uSec like 10 times the normal 30 uSec execution time of a "GOSUB" or something?

    I stand by my "it will run slower if you make lots of "RUN" calls"
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2008-09-17 18:57
    Allen,

    I agree that crossing slots will take more time. Marginally slower in the aggregate when there is only an occasional slot switch.

    It takes the BS2sx about 100 microseconds to execute a GOTO and longer for a GOSUB. A simple command like HIGH 0 takes about 55 microseconds on the BS2sx. The 300 us for RUN does not account for any additional branching within the new slot. Simply:
    LOW 0
    HIGH 0
    ' versus
    LOW 0   '<-- in slot 0
    RUN 1   ' in slot 0
    HIGH 0   ' this in slot 1, 300 microseconds longer due to the RUN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.