Optimizations

General FreeBASIC programming questions.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

Assuming that I guessed right in my previous post, this may be your solution:
  • IF BIT(&b001001001001001001001001001001001001001001001, bx + by + bz) THEN
(For bx + by + bz <= 46. You may adapt it up to values of 63.)
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Post by Gonzo »

nicely done, i definitely didnt see any aliasing or excessive corridoring :)
the pattern makes trees look less volumptuos and saves a bit of processing!
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Post by Gonzo »

what exactly does andalso and orelse do?
i read that they were short-circuiting so i guess they're like an early exit in programming terms?
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

This
  • IF a = b ANDALSO c = d THEN
is equal to
  • IF a = b THEN IF c = d THEN
The second expression (c = d) will only be checked if the first (a = b) does match.

Similar ORELSE: the second expression will only be checked if the first doesn't match.

You can speed up your code by puting time consuming computations (ie a function call) in the second expression.
yetifoot
Posts: 1710
Joined: Sep 11, 2005 7:08
Location: England
Contact:

Post by yetifoot »

Someone earlier in the thread asked why andalso/orelse are slow.

When i added those operators, I based them on top of IIF. It's certainly possible to do it much better, but that was the only way I could find at the time that worked correctly, so I decided it was better to have the operators, working correctly, but not well optimized, than not have the operators at all.
fxm
Moderator
Posts: 12576
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re:

Post by fxm »

yetifoot wrote:Someone earlier in the thread asked why andalso/orelse are slow.

When i added those operators, I based them on top of IIF. It's certainly possible to do it much better, but that was the only way I could find at the time that worked correctly, so I decided it was better to have the operators, working correctly, but not well optimized, than not have the operators at all.
Wanting an optimized program, I recently faced this problem and I still must code nested 'If'.
Consequently, I filled a feature request: Execution speed optimization of 'Andalso' and 'Orelse'
Post Reply