LBB very slow compare to LB ... any idea ?

Discussions about the Liberty BASIC language, with particular reference to LB Booster
atomose
Posts: 2
Joined: Mon Sep 30, 2024 7:20 am

LBB very slow compare to LB ... any idea ?

Post by atomose »

hi ! i try to up my program speed with LBB but i was surprised to see that LBB make a program 10x slowler ... have you any idea how is it possible ? thx

Code: Select all


  
    ' Life Simulation by Atomose Studio (2024) make with LibertyBasic 4.51 pro

    nomainwin
    GameVersion = 0.63 : UNIT = 100 : sizeEDITOR = 1 : Dx = 5000
    WindowWidth=807 : WindowHeight=630 : UpperLeftX=int((DisplayWidth-WindowWidth)/4) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    UpperLeftX2 = UpperLeftX
    XX= 800 : YY= 580 : redim p(XX,YY)
    dim CoorX(1000000),CoorY(1000000),valU(10000000),LIFE(1000000),natality(1000000), genetic(1000000), VittesseU(1000000)
    graphicbox #ini.info, 0, 0, 801, 22
    graphicbox #ini.main, 0, 22, 801, 580
    button #ini.log, "Log", [log], UL, 2, 1,40,20
    button #ini.pause, "Days", [pause], UL, 47, 1,40,20
    open "Life Simulator -  v ";GameVersion for window_nf as #ini
    #ini, "trapclose [quit]"
    print #ini.main, "down; fill ";240;" ";190;" ";150;"; size 2; color ";0;" ";140;" ";0
    print #ini.info, "down; fill white; font Cascadia_Code 8 ; color black; backcolor white"
    for x = 1 to 30000
        XX = int(rnd(1)*780+10) : YY = int(rnd(1)*565+5) : p(XX,YY)= 1000001 : print #ini.main, "size 2; color ";0;" ";140;" ";0;"; set ";XX;" ";YY;"; color ";0;" ";100;" ";0;"; set ";XX;" ";YY+2
    next x
    for n = 1 to UNIT
        CoorX(n) = int(rnd(1)*780+10) : CoorY(n) = int(rnd(1)*560+10) : genetic(n) = int(rnd(1)*5+1)
        if genetic(n) <= 4 then genetic(n) = 1 : Ngenetic1 = Ngenetic1 + 1 : LIFE(n) = 1000 : valU(n) = 1 : VittesseU(n) = 0
        if genetic(n) >= 5 then genetic(n) = 2 : Ngenetic2 = Ngenetic2 + 1 : LIFE(n) = 4000 : valU(n) = n : VittesseU(n) = 1
    next n
    #ini.info, "place 525 13 ;\"; "Editor : " : #ini.info, "place 720 13 ;\"; "Size :"
    print #ini.info, "size 15; color black; set ";590;" ";10;"; set ";610;" ";10;"; set ";630;" ";10;"; set ";650;" ";10;"; set ";670;" ";10;"; set ";690;" ";10
    print #ini.info, "size 13; color ";240;" ";190;" ";150;"; set ";590;" ";10;"; color ";150;" ";100;" ";230;"; set ";610;" ";10;"; color ";0;" ";180;" ";0;"; set ";630;" ";10;"; color darkgray; set ";650;" ";10;"; color white; set ";670;" ";10;"; color white; set ";690;" ";10
    print #ini.info, "size 8; color black; set ";765;" ";10;"; size 6; color red; set ";765;" ";10;"; size 14; color black; set ";785;" ";10;"; size 12; color white; set ";785;" ";10
    print #ini.info, "size 4; color black ; set ";670;" ";10;"; color blue; set ";690;" ";10;";font Cascadia_Code 8 ; color black; backcolor white; when leftButtonDown [select]; flush"
    #ini.main, "when leftButtonDown [position]; when leftButtonMove [terrain]; flush"
    gosub [log]
    on error goto [error]

    [boucle]
    scan
    day = day + 1
    dayW = dayW + 1
    if dayW >135000 then
        dayW = 0
        if logACTIVATION = 1 then goto [refreshLOG]
        if logACTIVATION = 0 then Dx = Dx + 135000
    end if

    if logACTIVATION = 1 and dayW mod 2 = 1 then
        #wg "size 1; color white   ; set "; int( 1 +dayW /200) +40; " "; (570 -Ngenetic1 /3)
        #wg "color red     ; set "; int( 1 +dayW /200) +40; " "; (570 -Ngenetic2 /3)
        #wg "color yellow  ; set "; int( 1 +dayW /200) +40; " "; 570
    end if

    print #ini.info, "discard; place 95 13 ;\"; day;"  |  Herbivors : ";Ngenetic1;"  (";death; " killed)  ";"|  Carnivors : ";Ngenetic2;"    "
    print #ini.main, "discard; size 2; color ";0;" ";140;" ";0

    for r = 1 to 5
        regenX = int(rnd(1)*780+10) : regenY = int(rnd(1)*565+5)
        if p(regenX,regenY) = 0 then print #ini.main, "color ";0;" ";140;" ";0;"; set ";regenX;" ";regenY;"; color ";0;" ";100;" ";0;"; set ";regenX;" ";regenY+2 : p(regenX,regenY) = 1000001 : p(regenX,regenY+1) = 1000001 : p(regenX,regenY+2) = 1000001
    next r

    for x = 1 to UNIT
        if (valU(x) = 0 or LIFE(x) <= 0) then goto [next]
        print #ini.main, "color ";240;" ";190;" ";150
        LIFE(x) = LIFE(x) - (1+VittesseU(x))
        select case genetic(x)
            case 1
                if LIFE(x) <= 0 then valU(x) = 0 : Ngenetic1 = Ngenetic1 - 1 : print #ini.main, "set ";CoorX(x);" ";CoorY(x) : p(CoorX(x),CoorY(x)) = 0 : goto [next]
                print #ini.main, "set ";CoorX(x);" ";CoorY(x)
            case 2
                if LIFE(x) <= 0 then valU(x) = 0 : Ngenetic2 = Ngenetic2 - 1 : print #ini.main, "color ";240;" ";190;" ";150;"; set ";CoorX(x);" ";CoorY(x) : p(CoorX(x),CoorY(x)) = 0 : goto [next]
                if (p(CoorX(x),CoorY(x)) <> 1000001 and p(CoorX(x),CoorY(x)) <> 1000000) then print #ini.main, "color ";240;" ";190;" ";150;"; set ";CoorX(x);" ";CoorY(x) : p(CoorX(x),CoorY(x)) = 0
                if ((p(CoorX(x),CoorY(x)) = 1000001 or p(CoorX(x),CoorY(x)-1) = 1000001 or p(CoorX(x),CoorY(x)+1) = 1000001 or p(CoorX(x)-1,CoorY(x)) = 1000001 or p(CoorX(x)+1,CoorY(x)) = 1000001)) then print #ini.main, "size 2; color ";0;" ";140;" ";0;"; set ";CoorX(x);" ";CoorY(x);"; color ";0;" ";100;" ";0;"; set ";CoorX(x);" ";CoorY(x)+2
        end select
        p(CoorX(x),CoorY(x)) = 0 : Mooving = int(rnd(1)*9+1)
        select case Mooving
           case 1
                if p(CoorX(x)+(1+VittesseU(x)),CoorY(x)) < 1000002 and (CoorX(x)+(1+VittesseU(x))) <795 then CoorX(x) = CoorX(x) + (1+VittesseU(x)) : CoorY(x) = CoorY(x) + 0
                if CoorX(x) >=790 then CoorX(x) = 5
            case 2
                if p(CoorX(x)+(1+VittesseU(x)),CoorY(x)) < 1000002 and p(CoorX(x),CoorY(x)+(1+VittesseU(x))) < 1000002 and (CoorY(x)+(1+VittesseU(x))) <575 and (CoorX(x)+(1+VittesseU(x))) <795 then CoorX(x) = CoorX(x) + (1+VittesseU(x)) : CoorY(x) = CoorY(x) + (1+VittesseU(x))
                if CoorX(x) >=790 and CoorY(x) >=570 then CoorX(x) = 5 : CoorY(x) = 5
            case 3
                if p(CoorX(x),CoorY(x)+(1+VittesseU(x))) < 1000002 and (CoorY(x)+(1+VittesseU(x))) <575 then CoorX(x) = CoorX(x) + 0 : CoorY(x) = CoorY(x) + (1+VittesseU(x))
                if CoorY(x) >=570 then CoorY(x) = 5
            case 4
                if p(CoorX(x)-(1+VittesseU(x)),CoorY(x)) < 1000002 and p(CoorX(x),CoorY(x)+(1+VittesseU(x))) < 1000002 and (CoorY(x)+(1+VittesseU(x))) <575 and (CoorX(x)-(1+VittesseU(x))) >1 then CoorX(x) = CoorX(x) - (1+VittesseU(x)) : CoorY(x) = CoorY(x) + (1+VittesseU(x))
                if CoorX(x) <5 and CoorY(x) >=570 then CoorX(x) =790 : CoorY(x) = 5
            case 5
                if p(CoorX(x)-(1+VittesseU(x)),CoorY(x)) < 1000002 and (CoorX(x)-(1+VittesseU(x))) >1 then CoorX(x) = CoorX(x) - (1+VittesseU(x)) : CoorY(x) = CoorY(x) + 0
                if CoorX(x) <5 then CoorX(x) = 790
            case 6
                if p(CoorX(x)-(1+VittesseU(x)),CoorY(x)) < 1000002 and p(CoorX(x),CoorY(x)-(1+VittesseU(x))) < 1000002 and (CoorY(x)-(1+VittesseU(x))) >1 and (CoorX(x)-(1+VittesseU(x))) >1 then CoorX(x) = CoorX(x) - (1+VittesseU(x)) : CoorY(x) = CoorY(x) - (1+VittesseU(x))
                if CoorX(x) <5 and CoorY(x) <5 then CoorX(x) = 790 : CoorY(x) = 570
            case 7
                if p(CoorX(x),CoorY(x)-(1+VittesseU(x))) < 1000002 and (CoorY(x)-(1+VittesseU(x))) >1 then CoorX(x) = CoorX(x) + 0 : CoorY(x) = CoorY(x) - (1+VittesseU(x))
                if CoorY(x) <5 then CoorY(x) = 570
            case 8
                if p(CoorX(x)+(1+VittesseU(x)),CoorY(x)) < 1000002 and p(CoorX(x),CoorY(x)-(1+VittesseU(x))) < 1000002 and (CoorY(x)-(1+VittesseU(x))) >1 and (CoorX(x)+(1+VittesseU(x))) <795 then CoorX(x) = CoorX(x) + (1+VittesseU(x)) : CoorY(x) = CoorY(x) - (1+VittesseU(x))
                if CoorX(x) >=790 and CoorY(x) <5 then CoorX(x) = 5 : CoorY(x) = 570
        end select

        select case genetic(x)
            case 1
                if (valU(p(CoorX(x)+1,CoorY(x))) = 1 or valU(p(CoorX(x)+1,CoorY(x)-1)) = 1 or valU(p(CoorX(x)-1,CoorY(x))) = 1 or valU(p(CoorX(x)-1,CoorY(x)-1)) = 1 or valU(p(CoorX(x),CoorY(x)+1)) = 1 or valU(p(CoorX(x)+1,CoorY(x)+1)) = 1 or valU(p(CoorX(x),CoorY(x)-1)) = 1 or valU(p(CoorX(x)-1,CoorY(x)+1)) = 1) and natality(x) > 20 then LIFE(x) = int((LIFE(x)/4)+1) : natality(x) = 0 : UNIT = UNIT + 1 : valU(UNIT) = 1 : CoorX(UNIT) = CoorX(x) : CoorY(UNIT) = CoorY(x) : LIFE(UNIT) = 1000 : Ngenetic1 = Ngenetic1 + 1 : genetic(UNIT) = 1 : VittesseU(UNIT) = 0
                if p(CoorX(x),CoorY(x)) = 1000001 and LIFE(x) < 5000 then LIFE(x) = LIFE(x) + 50 : natality(x) = natality(x) + 1 : p(CoorX(x),CoorY(x)) = x : print #ini.main, "color ";255;" ";255;" ";255;"; set ";CoorX(x);" ";CoorY(x)
                if p(CoorX(x),CoorY(x)) = 1000001 and LIFE(x) >= 5000 then print #ini.main, "color ";0;" ";140;" ";0;"; set ";CoorX(x);" ";CoorY(x) : p(CoorX(x),CoorY(x)) = x
                if p(CoorX(x),CoorY(x)) = 0 then print #ini.main, "color ";255;" ";255;" ";255;"; set ";CoorX(x);" ";CoorY(x) : p(CoorX(x),CoorY(x)) = x
                if natality(x) >= 100 and LIFE(x) > 800 then LIFE(x) = int((LIFE(x)/2)+1) : natality(x) = 0 : UNIT = UNIT + 1 : valU(UNIT) = 1 : CoorX(UNIT) = CoorX(x) : CoorY(UNIT) = CoorY(x) : LIFE(UNIT) = 1000 : Ngenetic1 = Ngenetic1 + 1 : genetic(UNIT) = 1 : VittesseU(UNIT) = 0
            case 2
                print #ini.main, "color ";0;" ";0;" ";255;"; set ";CoorX(x);" ";CoorY(x)
                if valU(p(CoorX(x)+1,CoorY(x))) = 1 then killed = p(CoorX(x)+1,CoorY(x)) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if valU(p(CoorX(x)+1,CoorY(x)-1)) = 1 then killed = p(CoorX(x)+1,CoorY(x)-1) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if valU(p(CoorX(x)-1,CoorY(x))) = 1 then killed = p(CoorX(x)-1,CoorY(x)) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if valU(p(CoorX(x)-1,CoorY(x)-1)) = 1 then killed = p(CoorX(x)-1,CoorY(x)-1) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if valU(p(CoorX(x),CoorY(x)+1)) = 1 then killed = p(CoorX(x),CoorY(x)+1) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if valU(p(CoorX(x)+1,CoorY(x)+1)) = 1 then killed = p(CoorX(x)+1,CoorY(x)+1) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if valU(p(CoorX(x),CoorY(x)-1)) = 1 then killed = p(CoorX(x),CoorY(x)-1) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if valU(p(CoorX(x)-1,CoorY(x)+1)) = 1 then killed = p(CoorX(x)-1,CoorY(x)+1) : valU(killed) = 0 : Ngenetic1 = Ngenetic1 - 1 : p(CoorX(x),CoorY(x)) = 0 : LIFE(x) = LIFE(x) + LIFE(killed) + 1 : natality(x) = natality(x) + 1 : death = death + 1 : LIFE(killed) = 0
                if natality(x) >= 2 then LIFE(x) = int((LIFE(x)/2)+1) : natality(x) = 0 : UNIT = UNIT + 1 : valU(UNIT) = UNIT : CoorX(UNIT) = CoorX(x) : CoorY(UNIT) = CoorY(x) : LIFE(UNIT) = 4000 : Ngenetic2 = Ngenetic2 + 1 : genetic(UNIT) = 2 : VittesseU(UNIT) = 1
        end select
        [next]
    next x
    if Ngenetic1 <= 5 then newHERB = newHERB + 1
        if newHERB > 600 then newHERB = 0 : UNIT = UNIT + 1 : valU(UNIT) = 1 : CoorX(UNIT) = int(rnd(1)*780+5) : CoorY(UNIT) = int(rnd(1)*560+5) : LIFE(UNIT) = 1000 : genetic(UNIT) = 1 : Ngenetic1 = Ngenetic1 +1 : VittesseU(UNIT) = 0
    if Ngenetic2 <= 2 then newCARN = newCARN + 1
        if newCARN > 1800 then newCARN = 0 : UNIT = UNIT + 1 : valU(UNIT) = UNIT : CoorX(UNIT) = int(rnd(1)*780+5) : CoorY(UNIT) = int(rnd(1)*560+5) : LIFE(UNIT) = 4000 : genetic(UNIT) = 2 : Ngenetic2 = Ngenetic2 +1 : VittesseU(UNIT) = 1
    goto [boucle]

    [select]
    mX = MouseX : mY = MouseY : antifreeeze = 0
    print #ini.info, "size 2; color white; set ";683;" ";3;"; set ";663;" ";3;"; set ";643;" ";3;"; set ";623;" ";3;"; set ";603;" ";3;"; set ";582;" ";3
    if mX >580 and mX<598 then competence = 1 : pause = 1 : print #ini.pause, "Play"
    if mX >602 and mX<617 then competence = 2 : pause = 1 : print #ini.pause, "Play"
    if mX >623 and mX<637 then competence = 3 : pause = 1 : print #ini.pause, "Play"
    if mX >644 and mX<657 then competence = 4 : pause = 1 : print #ini.pause, "Play"
    if mX >662 and mX<678 then competence = 5 : pause = 1 : print #ini.pause, "Play"
    if mX >682 and mX<698 then competence = 6 : pause = 1 : print #ini.pause, "Play"
    if competence = 1 then print #ini.info, "color blue; set ";582;" ";3
    if competence = 2 then print #ini.info, "color blue; set ";603;" ";3
    if competence = 3 then print #ini.info, "color blue; set ";623;" ";3
    if competence = 4 then print #ini.info, "color blue; set ";643;" ";3
    if competence = 5 then print #ini.info, "color blue; set ";663;" ";3
    if competence = 6 then print #ini.info, "color blue; set ";683;" ";3
    if mX >755 and mX<775 then sizeEDITOR = 1 : print #ini.info, "size 8; color black; set ";765;" ";10;"; size 6; color red; set ";765;" ";10;";size 14; color black; set ";785;" ";10;"; size 12; color white; set ";785;" ";10
    if mX >775 and mX<795 then sizeEDITOR = 2 : print #ini.info, "size 14; color black; set ";785;" ";10;"; size 12; color red; set ";785;" ";10;";size 8; color black; set ";765;" ";10;"; size 6; color white; set ";765;" ";10
    print #ini.info, "color black"
    if pause = 1 then wait
    goto [boucle]

    [position]
    mX = MouseX : mY = MouseY
    if competence = 5 then UNIT = UNIT + 1 : valU(UNIT) = 1 : CoorX(UNIT) = MouseX : CoorY(UNIT) = MouseY : LIFE(UNIT) = 1000 : Ngenetic1 = Ngenetic1 + 1 : genetic(UNIT) = 1 : print #ini.main, "size 2; color ";255;" ";255;" ";255;"; set ";CoorX(UNIT);" ";CoorY(UNIT)
    if competence = 6 then UNIT = UNIT + 1 : valU(UNIT) = 2 : CoorX(UNIT) = MouseX : CoorY(UNIT) = MouseY : LIFE(UNIT) = 4000 : Ngenetic2 = Ngenetic2 + 1 : genetic(UNIT) = 2 : print #ini.main, "size 2; color ";0;" ";0;" ";255;"; set ";CoorX(UNIT);" ";CoorY(UNIT)
    if pause = 1 then wait
    goto [boucle]

    [terrain]
    select case sizeEDITOR
        case 1
            select case competence
                case 1
                    print #ini.main, "size 1; color ";240;" ";190;" ";150 : valor = 0 : gosub [sizeEDITOR1]
                case 2
                    print #ini.main, "size 1; color ";150;" ";100;" ";230 : valor = 1000002 : gosub [sizeEDITOR1]
                case 3
                    print #ini.main, "size 1; color ";0;" ";140;" ";0 : valor = 1000001 : gosub [sizeEDITOR1]
                case 4
                    print #ini.main, "size 1; color ";100;" ";110;" ";110 : valor = 1000003 : gosub [sizeEDITOR1]
                end select
        case 2
            select case competence
                case 1
                    print #ini.main, "size 1; color ";240;" ";190;" ";150 : valor = 0 : gosub [sizeEDITOR2]
                case 2
                    print #ini.main, "size 1; color ";150;" ";100;" ";230 : valor = 1000002 : gosub [sizeEDITOR2]
                case 3
                    print #ini.main, "size 1; color ";0;" ";140;" ";0 : valor = 1000001 : gosub [sizeEDITOR2]
                case 4
                    print #ini.main, "size 1; color ";100;" ";110;" ";110 : valor = 1000003 : gosub [sizeEDITOR2]
            end select
    end select
    if pause = 1 then wait
    goto [boucle]

    [log]
    if logACTIVATION = 1 then goto [boucle]
    WindowWidth=807 : WindowHeight=630 : UpperLeftX= UpperLeftX2 + WindowWidth +20 : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    open "Log Pop/Time" for graphics_nsb_nf as #wg
    [refreshLOG]
    #wg "trapclose [quitLOG]; down ; fill 240 190 150 ; size 1"
    print #wg, "color black; font Cascadia_Code 7 ; backcolor 240 190 150"
    print #wg, "place 745 575 ;\"; "Days"
    print #wg, "place 15 20 ;\"; "Pop"
    print #wg, "place 10 65 ;\"; "1500"
    print #wg, "place 10 145 ;\"; "1250"
    print #wg, "place 10 230 ;\"; "1000"
    print #wg, "place 15 315 ;\"; "750"
    print #wg, "place 15 400 ;\"; "500"
    print #wg, "place 15 485 ;\"; "250"
    print #wg, "line "; 40; " "; 20; " "; 40; " "; 570
    print #wg, "line "; 40; " "; 570; " "; 740; " "; 570
    print #wg, "line "; 35; " "; 65; " "; 45; " "; 65
    print #wg, "line "; 35; " "; 145; " "; 45; " "; 145
    print #wg, "line "; 35; " "; 230; " "; 45; " "; 230
    print #wg, "line "; 35; " "; 315; " "; 45; " "; 315
    print #wg, "line "; 35; " "; 400; " "; 45; " "; 400
    print #wg, "line "; 35; " "; 485; " "; 45; " "; 485
    wX = 26
    print #wg, "font Cascadia_Code 6"
    for w = 1 to 26
        print #wg, "line "; 40+wX; " "; 568; " "; 40+wX; " "; 575
        if DxD = 1 then print #wg, "place "; 30+wX; " 590 ;\"; Dx : DxD = 0 : wX = wX+26 : Dx = Dx +5000 : goto [noDxD]
        wX = wX+26 : Dx = Dx +5000 : DxD = 1
        [noDxD]
    next w
    #wg "flush" : logACTIVATION = 1 : goto [boucle]

    [sizeEDITOR1]
    p(MouseX,MouseY)   = valor : p(MouseX+1,MouseY)   = valor : p(MouseX-1,MouseY)   = valor : print #ini.main, "set ";MouseX;" ";MouseY   ;"; set ";MouseX+1;" ";MouseY   ;"; set ";MouseX-1;" ";MouseY
    p(MouseX,MouseY+1) = valor : p(MouseX+1,MouseY+1) = valor : p(MouseX-1,MouseY+1) = valor : print #ini.main, "set ";MouseX;" ";MouseY+1 ;"; set ";MouseX+1;" ";MouseY+1 ;"; set ";MouseX-1;" ";MouseY+1
    p(MouseX,MouseY-1) = valor : p(MouseX+1,MouseY-1) = valor : p(MouseX-1,MouseY-1) = valor : print #ini.main, "set ";MouseX;" ";MouseY-1 ;"; set ";MouseX+1;" ";MouseY-1 ;"; set ";MouseX-1;" ";MouseY-1
    return
    [sizeEDITOR2]
    p(MouseX,MouseY)   = valor : p(MouseX+1,MouseY)   = valor : p(MouseX+2,MouseY)   = valor : p(MouseX-1,MouseY)   = valor : p(MouseX-2,MouseY)   = valor : print #ini.main, "set ";MouseX;" ";MouseY   ;"; set ";MouseX+1;" ";MouseY   ;"; set ";MouseX+2;" ";MouseY   ;"; set ";MouseX-1;" ";MouseY   ;"; set ";MouseX-2;" ";MouseY
    p(MouseX,MouseY+1) = valor : p(MouseX+1,MouseY+1) = valor : p(MouseX+2,MouseY+1) = valor : p(MouseX-1,MouseY+1) = valor : p(MouseX-2,MouseY+1) = valor : print #ini.main, "set ";MouseX;" ";MouseY+1 ;"; set ";MouseX+1;" ";MouseY+1 ;"; set ";MouseX+2;" ";MouseY+1 ;"; set ";MouseX-1;" ";MouseY+1 ;"; set ";MouseX-2;" ";MouseY+1
    p(MouseX,MouseY+2) = valor : p(MouseX+1,MouseY+2) = valor : p(MouseX+2,MouseY+2) = valor : p(MouseX-1,MouseY+2) = valor : p(MouseX-2,MouseY+2) = valor : print #ini.main, "set ";MouseX;" ";MouseY+2 ;"; set ";MouseX+1;" ";MouseY+2 ;"; set ";MouseX+2;" ";MouseY+2 ;"; set ";MouseX-1;" ";MouseY+2 ;"; set ";MouseX-2;" ";MouseY+2
    p(MouseX,MouseY-1) = valor : p(MouseX+1,MouseY-1) = valor : p(MouseX+2,MouseY-1) = valor : p(MouseX-1,MouseY-1) = valor : p(MouseX-2,MouseY-1) = valor : print #ini.main, "set ";MouseX;" ";MouseY-1 ;"; set ";MouseX+1;" ";MouseY-1 ;"; set ";MouseX+2;" ";MouseY-1 ;"; set ";MouseX-1;" ";MouseY-1 ;"; set ";MouseX-2;" ";MouseY-1
    p(MouseX,MouseY-2) = valor : p(MouseX+1,MouseY-2) = valor : p(MouseX+2,MouseY-2) = valor : p(MouseX-1,MouseY-2) = valor : p(MouseX-2,MouseY-2) = valor : print #ini.main, "set ";MouseX;" ";MouseY-2 ;"; set ";MouseX+1;" ";MouseY-2 ;"; set ";MouseX+2;" ";MouseY-2 ;"; set ";MouseX-1;" ";MouseY-2 ;"; set ";MouseX-2;" ";MouseY-2
    return

    [pause]
    if pause = 1 then pause = 0 : competence = 0 : print #ini.info, "size 2; color white; set ";683;" ";3;"; set ";663;" ";3;"; set ";643;" ";3;"; set ";623;" ";3;"; set ";603;" ";3;"; set ";582;" ";3 : print #ini.info, "color black" : print #ini.pause, "Days" : goto [boucle]
    if pause = 0 then pause = 1 : print #ini.pause, "Play" : wait
    [quitLOG]
    close #wg : logACTIVATION = 0 : goto [boucle]
    [quit]
    close #ini
    if logACTIVATION = 1 then close #wg
    end
    [error]
    wait


guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: LBB very slow compare to LB ... any idea ?

Post by guest »

atomose wrote: Mon Sep 30, 2024 7:26 am have you any idea how is it possible ?
One situation in which LBB will run more slowly (possibly much more slowly) than LB4 is when a native language statement or function in Liberty BASIC has to be emulated by interpreted BASIC code in LBB, because there is no exact BBC BASIC equivalent.

An example of this is WORD$(), which is a native (built-in) function in Liberty BASIC but is emulated by this relatively complex code in LBB:

Code: Select all

      DEF FN_word$(A$, N%, T$)
      LOCAL A%, I%, J%
      IF N%<FALSE THEN = ""
      IF T$="" THEN
        A$ = FN_trim$(A$)
        A% = !^A$-1
        FOR I% = 1 TO LENA$
          IF A%?I%<&20 MID$(A$,I%,1) = " "
        NEXT
        T$ = " "
      ENDIF
      I% = 1 : J% = 1
      WHILE N%
        IF A% WHILE A%?I%=&20 I% += 1 : ENDWHILE
        J% = I%
        I% = INSTR(A$, T$, I%)
        IF I%=FALSE I% = LENA$+1
        I% += LENT$
        N% -= 1
      ENDWHILE
      IF I%=J% OR J%>LENA$ THEN = ""
      IF I%=J%+LENT$ THEN = T$
      = MID$(A$, J%, I%-J%-LENT$)
There are several other similar cases. Generally, LBB will run faster than LB4 if BBC BASIC has an identical or very similar function to the Liberty BASIC one, but may well run slower if it doesn't, particularly if it's a relatively complicated function.

Use the LBB Profiler to discover where the slow-down is occurring, that's what it's for. Having found the section of your program which is running slowly, try to rewrite it in a more 'BBC BASIC friendly' fashion!

Or simply use Liberty BASIC. There will always be some programs which are better suited to running in the original language (or have to, because they rely on a feature LBB doesn't have, such as arbitrary-precision integer arithmetic).
atomose
Posts: 2
Joined: Mon Sep 30, 2024 7:20 am

Re: LBB very slow compare to LB ... any idea ?

Post by atomose »

hi ! thx for answer.

I used profiler and the slow line are

Code: Select all

print #ini.main, "color ";240;" ";190;" ";150
or

Code: Select all

print #ini.main, "set ";CoorX(x);" ";CoorY(x)
are they the same in BBC BASIC synthaxe ? (where can i have all the BBC BASIC synthaxe ?)
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: LBB very slow compare to LB ... any idea ?

Post by guest »

atomose wrote: Mon Sep 30, 2024 10:39 am I used profiler and the slow line are

Code: Select all

print #ini.main, "color ";240;" ";190;" ";150
or

Code: Select all

print #ini.main, "set ";CoorX(x);" ";CoorY(x)
Plotting individual pixels on the screen is a very inefficient way of drawing graphics, not least because it will involve at least two OS API calls for every single pixel (one to set the color, one to do the plotting); I am not at all surprised it is slow.

If you cannot draw your graphics using 'higher level' objects such as lines, rectangles, circles etc. then there is probably nothing much you can do to speed it up; sorry.

It would probably be a lot faster to keep a bitmap in memory and modify that, then when it is complete blit the entire bitmap to the screen in one go. But that would obviously involve a major revision to the way your program works.

I would conclude that your program is not suited to be run in LBB, and you should probably use Liberty BASIC 4.