News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Decreasing a variable by one

Started by baggey, November 24, 2012, 02:57:43 PM

Previous topic - Next topic

baggey

Anyone know, whats the quickest way of doing the above

PlayBASIC Code: [Select]
1:   reghl_=reghl_-1

2: dec reghl_,1

3: reghl_--




Or should i say whick is the quickest 1,2 or 3  ::)

Kind regards Baggey
Jesus was only famous because of his dad

daver

#3 is less characters. In this case it's the only "quickest way" that matters...IMHO.

If you are in a tight loop doing this a million times I would suggest writing a test harness that gets the time at the start, loops a million times and gets the time at the end. Do this for each scenario and see what result you get.

Will you ask this question when writing your graphics code? That's where performance optimizations will really make a difference.


kevin

#2
QuoteOr should i say whick is the quickest 1,2 or 3

 In modern versions of PB,  they're all the same operation.  In legacy versions, INC/DEC used to be special case operations, but over time they became slower than standard subtract and add, as such they're recast as sub/add.  

baggey

QuoteWill you ask this question when writing your graphics code? That's where performance optimizations will really make a difference.

Thanks for the hint  using a timer to wrap code ;)

In most cases i always use the 'C' style operator.

As the Emulator is coming on. Im finding certain approaches create a bottle neck and others seem to whizz on!

The Graphics emulation is already done! Kevin looked over some of my code and its running as fast as we can get it  ;D

So, in a nutshell 'C' style is my preferred approach, and in Playbasic there all the same!

Thanks Peep's!

Baggey
Jesus was only famous because of his dad

kevin

Quotefast as we can get it

  we ? ... no..

baggey

Jesus was only famous because of his dad