Shop OBEX P1 Docs P2 Docs Learn Events
how do you calculate code overhead? — Parallax Forums

how do you calculate code overhead?

krupakrupa Posts: 3
edited 2006-06-23 14:05 in BASIC Stamp
I'm slowly working through "Robotics with the Boe-bot" and I'm wondering how they came to the number 1.3 ms for the time to execute the FOR loop. Or maybe I already know, since my math seems to work out, but confirmation would be nice.

Here's what I'm thinking:

The BS2 spec gives the execution speed at ~4000 instructions per second which is 0.25 ms / instruction.

If the for loop is:
for x = 1 to 20
  ' instruction 1
  ' instruction 2
next




The assembly breaks down to something like this:
for:
     cmp x, 20
     je end
          ' instruction 1
          ' instruction 2
     inc x
     jmp for
end:




Which means a for loop is actually four instructions at 0.25 ms / instruction makes 1.25 ms or ~1.3 ms as stated in the book.

Is this correct or just a coincidence? If it's the latter, how do you know how long complex instructions take to run?

Thanks

Post Edited (krupa) : 6/23/2006 3:16:08 AM GMT

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-06-23 05:31
    krupa -

    Breaking it down to assembler is not a good idea, since PBASIC is an interpreted language. Here is a list of many of the PBASIC commands, and thier timings:
    http://www.emesystems.com/BS2speed.htm

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-06-23 14:05
    Hmm.

    Well, a "FOR" loop does have to do several things, so it would make sense that it would take longer than some other "simple" instructions (Like VarA = VarA + 1 would be very simple).

    However, the way the BS2 works is, each PBasic keyword (like "FOR") gets compiled into a 'Token' (an integer, like 40).

    Then, the BS2's PIC (a 16C57) is programmed to read each 'token', and call 'library code' (PIC assembly burned into the PIC) which executes the functionality of the "FOR". (Note all actual values in this explanation are made up -- I have no idea what token value 'FOR' actually compiles to).

    This is why the 20 Mhz PIC seems to be running at about 4000 PBasic instructions per second. Each token has to be fetched from the external eeprom, looked up, library code run, and the next token fetched.

    On the good side, this gives you a very simple, easy to debug, easy to program platform. For those benefits you sacrifice some speed.

    But yes, you can't really convert to assembly and make conclusions from that. Instead, use the BS2Speed.htm table.·· http://www.emesystems.com/BS2speed.htm
Sign In or Register to comment.