Optimizations

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

Postby TJF » May 08, 2011 21:41

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

Postby Gonzo » May 08, 2011 21:50

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

Postby Gonzo » May 09, 2011 22:26

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: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » May 10, 2011 6:45

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:

Postby yetifoot » Jul 13, 2011 2:59

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
Posts: 9528
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re:

Postby fxm » May 12, 2012 10:21

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'

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest