Shop OBEX P1 Docs P2 Docs Learn Events
Question on code performance — Parallax Forums

Question on code performance

tdahburatdahbura Posts: 6
edited 2010-11-17 09:21 in Propeller 1
I am wondering if anyone has any benchmarks on spin code versus assembler code performance on the propeller. I know this is not something that is easily compared but was curious if anyone had taken a simple problem and coded it in spin and assembly to see how it performs....

I am not real up to speed on spin assembly to write two equivalent programs.

Thanks,
Tony

Comments

  • Miner_with_a_PICMiner_with_a_PIC Posts: 123
    edited 2010-11-12 03:33
    When first starting out with the Propeller I discovered that spin became a speed limiter for some projects. Digging a little deeper using an oscilloscope the following loop took 1420 clock cycles to complete. A similar loop written in assembly took 12 cycles, so a factor of 118.

    repeat

    outa[15] :=1
    outa[15] :=0

    When speed becomes a concern, assembly can be peppered into a project to deal with speed intensive tasks while Spin can act to coordinate/supervise activities.
  • Christof Eb.Christof Eb. Posts: 1,247
    edited 2010-11-12 03:46
    Hi Tony,

    you might want to have a look at PropBasic, because with this tool you can write programs in Basic language, which are compiled to assembler and can be executed directly like assembler. If needed, you can use the inline assembler later too.

    Christof
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-11-12 07:11
    The neat thing about the Propeller is that one can use its cnt register to do timing tests in Spin and PASM. The Propeller Q&A site has code samples for both.

    -- http://www.parallax.com/portals/0/propellerqna
  • localrogerlocalroger Posts: 3,452
    edited 2010-11-12 14:29
    It strongly depends on what you're doing, but the usual figure given is that Spin is about 50 times slower than PASM -- faster than that for some things, slower for others.

    As JonnyMac mentions Spin can do much more accurate timing than it should be able to by using the WAIT* functions, as long as that timing isn't ultra-fast. Spin has been shown to be fast enough to implement a passable serial UART at 19200 baud (see the SimpleSerial object), but PASM can implement four of them at several hundred kilobaud in one cog.

    Creative use of the counter/timers can also make it possible for Spin to generate much higher frequency PWM and other pulse phenomena than would normally be possible with a language of its latency.
  • tdahburatdahbura Posts: 6
    edited 2010-11-17 04:53
    Thanks everyone for the insight!

    I decided to get my feet wet in some propeller assembly and was able to get sample programs working. Tried some timing code for the spin interpreted language and came up with a similar method to what was mentioned in the Q&A.

    Now I need to try some different examples out and record the results. If I can get enough concrete samples I will post them to the forum.

    Thanks,
    Tony
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-11-17 09:21
    localroger wrote: »
    It strongly depends on what you're doing, but the usual figure given is that Spin is about 50 times slower than PASM -- faster than that for some things, slower for others.
    I would venture to guess PASM is more than 50 times faster for most things. Just a few simple tests (like what Miner did), and others like retrieving CNT (95x faster) show much higher yields.

    I wrote an ADC IC driver in SPIN it was only able to do 26 samples per second (albeit, it was early on in my Propeller career, so it might not have been the most optimized bit of software, but it wasn't poorly written). Now I have a PASM driver that has way more features, and it can run at almost 2400 samples per second. Again, over 90 times faster, but if I stripped away the additional features so it ran like the SPIN version, it would likely be close to 2800 samples per second.
Sign In or Register to comment.