Shaving microseconds, ideas needed.

Buzby

Senior Member
Hi All,

Some of you have an avid interest in the execution speed of Picaxe instructions, so you may know the answer already.

I need to shave every last microsecond off the execution time of a routine which has the following requirement.

The 'lookup' instruction is slow, but is it slower than three maths instructions ?

Or can hippy come up with a bit-twiddle solution that's faster than both my ideas ?

Code:
Var1 has a value from 1 to 9. Using Var1, set Var2 to the result 4 to 20.

Which is quickest ?

        Var2 = Var1 - 1 * 2 + 4
 or
       lookup Var1, (0,4,6,8,10,12,14,16,18,20), Var2
Cheers,

Buzby
 

Buzby

Senior Member
... or am I missing something?
Err, no !. It's me missing the b****** obvious !.

That's what comes of overthinking a problem at 1am, after a tough day at work, a four hour drive home, and a couple of single malts.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
Var2 = Var1 * 2 + 2

And that can be optimised to -

Var2 = Var1 + Var1 + 2

The fastest option may be -
Code:
Read Var1, Var2

Data 1, (4)
Data 2, (6)
Data 3, (8)
Data 4, (10)
Data 5, (12)
Data 6, (14)
Data 7, (16)
Data 8, (18)
Data 9, (20)
You could use READTABLE and TABLE where available.
 

Buzby

Senior Member
Var2 = Var1 + Var1 + 2

The fastest option may be -

Read Var1, Var2
This is where two heads are better than one !.

The 'READ' method is a good way to solve this problem, and will really come into it's own a bit later in the prog, where I need to lookup a non-mathematically-related result.

Thanks,

Buzby
 
Top