Shop OBEX P1 Docs P2 Docs Learn Events
Comparison speeds... — Parallax Forums

Comparison speeds...

ArchiverArchiver Posts: 46,084
edited 2002-04-16 08:53 in General Discussion
Hello Stamp Guru's...
Is it faster to compare the lower nibbles of 2 bytes than it is to compare the
whole 2 bytes, for example:
Is...
if byte1 <> byte2 then DoSomething

slower than...
if byte1.lownib <> byte2.lownib then DoSomething

I have to compare chunks of 3 bytes in a table of 10000 bytes in an Eeprom, so
it gets a bit tedious.
Also, how much faster is the I2C command in the bs2p than the shiftin / shiftout
routines when used with a bs2sx.
Any help appreciated...
Thanks in advance,
Chris




[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-04-16 08:43
    >Hello Stamp Guru's...
    >Is it faster to compare the lower nibbles of 2 bytes than it is to
    >compare the whole 2 bytes, for example:
    >Is...
    >if byte1 <> byte2 then DoSomething
    >
    >slower than...
    >if byte1.lownib <> byte2.lownib then DoSomething

    The guruvy way to find out is to ask the ultimate authority, the
    stamp itself. With stopwatch in hand, try the following program:
    x var word
    y var byte
    for x=1 to 10000
    if y.byte0<>y.byte1 then gonext
    toggle 1
    gonext:
    next
    Then substitute y.nib0 and y.nib 1 in the decision, and compare the
    times for 10000 trips around the loop. (Or measure the frequency on
    p1 with a counter) My guess is that it will be pretty much a wash.
    The nib form may take slightly longer, because the address of a nib
    in memory is longer than the address of the byte. What that means is
    that the interpreter has a slightly longer instruction to read out of
    the eeprom. There are 32 bytes in the RAM space, and 64 nibs, so it
    takes a 6 bit address versus a 5 bit address. However, the stamp
    interpreter stores powers of two like 0,1,2,4 in an especially
    compact format, so you may find dealing with x.nib3 to be different
    from x.nib2. There are always these fine points of difference
    depending on where the variable happens to fall in memoryh. But in
    the main, the speed of the Stamp depends on the number of bits that
    the interpreter has to read from the eeprom prior to executing the
    instruction.

    >I have to compare chunks of 3 bytes in a table of 10000 bytes in an
    >Eeprom, so it gets a bit tedious.
    >Also, how much faster is the I2C command in the bs2p than the
    >shiftin / shiftout routines when used with a bs2sx.

    In general, I2C is a slower protocol than SPI (Shiftin/out). I think
    on the BS2p the I2C command can have several parameters, and it takes
    time for the interpreter to read them out of eeprom. I have not done
    any specific tests though.

    >Any help appreciated...
    >Thanks in advance,
    >Chris

    HTH.
    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2002-04-16 08:53
    Thanks for the reply Tracy, as I sort of thought, no great advantage either
    way.

    Regards,
    Chris
Sign In or Register to comment.