Bugs

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Bugs

Post by Munair »

deltarho[1859] wrote: Feb 23, 2022 14:01 PowerBASIC is not open source, so I doubt that we ever know how Bob mangaged to get his string handling functions to run so fast.
Since November I've been working on implementing strings (const, var and fixed). What I've been very keen on is to only copy a string if really necessary (e.g. to break away from existing reference). I don't know if PB uses a garbage collector or reference counting, but I chose the latter, which may have some impact on performance. But I doubt it will be much.

BTW, I have not yet implemented a timer function, so I cannot do any comparison at this point.
Last edited by Munair on Feb 23, 2022 14:43, edited 1 time in total.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

deltarho
Could you make a dll file using powerbasic function str so we can try it out.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Bugs

Post by deltarho[1859] »

dodicat wrote:deltarho
Could you make a dll file using powerbasic function str so we can try it out.
Why would you want any more than the example I gave above?

In my experience dlls do not run as fast as compiled source code so comparing a PowerBASIC dll with a FreeBASIC compiled source code or vice versa is not very illuminating. My FreeBASIC PCG32II was compiled to a dll for PowerBASIC use, but it ran a lot slower than the FreeBASIC compiled source code. The best approach is to have access to both compilers.

If you give me some test examples, I will run them with PowerBASIC for you.

We need to work out a cost per test, but I do bulk discounts. :roll:
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

OK deltarho, about .4 seconds for the million loop, about the same as freepascal.
Remember that you can now compile your freebasic dll with full gcc optimisation and it will pass over optimized.
In Version < 1.08 (I think), the optimisation switch (-O3 or whatever) was ignored when using -dll switch.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Bugs

Post by deltarho[1859] »

dodicat wrote:In Version < 1.08 (I think), the optimisation switch (-O3 or whatever) was ignored when using -dll switch.
I did not know that. :o

I'll do a recompilation.

Added: and got a 15% speed increase. :x
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bugs

Post by fxm »

Munair wrote: Feb 23, 2022 11:06
fxm wrote: Feb 23, 2022 10:34 The same principle of tests (only at compile-time) are also applied to the initialization of all numeric variables (Byte, Short, Long, ...)
Yes, but as I already explained, the test should not apply to boolean because it doesn't have a range nor values that are used numerically that might affect the outcome of an arithmetic operation. In short, cbool(10) is not a critical conversion, so any warning here is pointless.

To wrap this up, I do not consider the compile-time warning a bug but rather a design issue.
A simple workaround to return 'Cbool(x)' without any warning is to use instead 'Cbool(x <> 0)'.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Bugs

Post by Munair »

fxm wrote: Feb 23, 2022 19:13 A simple workaround to return 'Cbool(x)' without any warning is to use instead 'Cbool(x <> 0)'.
Yes, because the argument is turned into an expression, which basically has the same effect as passing a variable: no range check.
KLBear
Posts: 113
Joined: Jul 23, 2008 9:32

Re: Bugs

Post by KLBear »

Is this a bug or did something change in the latest version. I am using FreeBasic version 1.09 this program keeps running. I found out why it' won't exit when counting down to 0 its the Unsigned variable. The work around is if x = 0 Then exit for after the print statement. I still don't know if this is a bug or not.

Code: Select all

DIM AS USHORT pitch,x
pitch = 300

'for x = pitch to 1 step -1 'this stops at 1

for x = pitch to 0 step -1 ' this keeps running when counting down to 0
print x
' if you uncomment the next line it works.
' if x = 0 Then exit for 
next
print "Ended"
sleep
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Bugs

Post by SARG »

Due to the way thing is done and the use of unsigned integer.
SInce 1.08 there is a warning :KLBear.bas(6) warning 45(1): FOR counter variable is unable to exceed limit value

Try with short datatype for x.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bugs

Post by fxm »

Extract of the FOR...NEXT documentation page:
.....
Note: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds endvalue, which can never happen.
.....
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Bugs

Post by marcov »

deltarho[1859] wrote: Feb 23, 2022 14:01 He even wrote a 'Stringbuilder object' which executed at lightning speed because he was not happy with the speed of the standard concatenation operators.
Stringbuilders come from Java and most newer languages have them, sometimes via C#/VB.NET that copied the behaviour.

Stringbuilders mostly fix the pattern of people generating webpages with basic string support, stressing the concat operator with sometimes megabytes worth of strings.

The origins however are in the immutable string concept of Java.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Bugs

Post by marcov »

Munair wrote: Feb 23, 2022 14:14 I don't know if PB uses a garbage collector or reference counting, but I chose the latter, which may have some impact on performance. But I doubt it will be much.
I'm no GC expert, but have read a bit about them and found the following rule of thumbs for garbage collection/ref counting:

- ref count is generally faster.
- but suffers from cycles if used for general objects, and dealing with that can be costly. Not applicable to e.g. strings.
- GC is slow, but certain high level kinds (used for high level scripting languages that generate an allocation for just about everything) scale somewhat better with the large amounts of fairly temporary allocations. Typically these are of the generational and moveable (can move an allocation) type.
- the various GCs that can be retrofitted to existing languages are usually not in this category.
- many GCs have a global lock during garbage collection time and may cause all threads that try to allocate to block.
- ref counts rely on malloc that often also has a global lock with straightforward malloc implementations, but the delays are much shorter. More advanced malloc implementations have heapmanager state per thread to avoid too frequent global locks, and to increase heapperformance in threads.
- Still needs global lock if you allocate in one thread and deallocate in the other. In frequent cases this can be mitigated with simple manual pooling of those (typically messenger-) objects.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

Job- to get the closest 20 points to a point outside a radius 80 from the point.
Problem:
I have type pt ( 2D point) and type arrayofpoints.
But the two subs are accepting type arrayofpoints as type pt and treating the arrayofpoints as an array of pt.
Tested 32/64/gen gas64

Code: Select all

#cmdline "-exx"

type pt
    as single x,y
end type

type arrayofpoints
      as pt a(any)
end type

sub GetClosest(a() as pt,ans() as pt,v as pt,num as long,rad as long)
     #define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius
     dim as single r=rad,ctr
    do
        r+=.5
        ctr=0
    for n as long=lbound(a) to ubound(a)
        if incircle(v.x,v.y,r,a(n).x,a(n).y) and incircle(v.x,v.y,rad,a(n).x,a(n).y)=0 then
            ctr+=1
            redim preserve ans(1 to ctr)
            ans(ctr)=a(n)
      end if
    next n
loop until ubound(ans)>=num
redim preserve ans(1 to num)
circle(v.x,v.y),rad,rgba(0,200,0,100)
circle(v.x,v.y),5,rgb(255,255,255),,,,f
end sub

sub drawpoints(p() as pt,col as ulong)
      for n as long=lbound(p) to ubound(p)
            circle (p(n).x,p(n).y),4,col
            draw string(p(n).x+3,p(n).y),str(n),rgba(200,200,200,200)
            next n
      end sub


dim as pt p(1 to 100)
dim as pt v=type(400,300)
redim as arrayofpoints result()

for n as long=1 to ubound(p)
      p(n)=type(rnd*800,rnd*600)
next
screen 19,32,,64

getclosest(p(),result(),v,20,80)


for n as long=1 to ubound(p)
      pset(p(n).x,p(n).y),rgb(255,255,255)
next

drawpoints(result(),rgba(0,200,0,100))

sleep

 
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bugs

Post by fxm »

dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

Thanks, I remember it now.
Post Reply