LB Booster
« Long strings »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:17am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Long strings  (Read 528 times)
HugoS
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Long strings
« Thread started on: Mar 26th, 2016, 6:31pm »

Hope this hasn't been addressed before - I did search the forum but zero results were shown.

I have found LBB to be many, many times faster than LB in all respects except when looping through long strings with the word$() function. To put this in perspective, the below code executes in about 15 seconds in LB 4.5, whereas in LBB I gave up somewhere around the 15 minute mark with no end in sight. Appreciate that the easy solution is to split a long string into smaller chunks but I have a good reason for not doing this.

Anyone else experienced the same issue? Is there a workaround? Is it a bug?

The below is just an example so I don't have to upload a data file. grin

let test$ = httpget$("http://www.dailymail.co.uk/home/index.html")
let aPos = instr(test$, "<body")
let bPos = instr(test$, "</body>")
let aFile$ = mid$(test$, aPos, bPos - aPos)

let a$ = "huh"
while a$ <> ""
index = index + 1
a$ = lower$(word$(aFile$, index))
if a$ = "james" then
let aCnt = aCnt + 1
end if
wend
notice aCnt

function httpget$(url$)
open "WININET.DLL" for dll as #net
calldll #net, "InternetOpenA", "LB Booster" as ptr, 0 as long, _
0 as long, 0 as long, 0 as long, hnet as ulong
calldll #net, "InternetOpenUrlA", hnet as ulong, url$ as ptr, _
"" as ptr, 0 as long, 0 as long, 0 as long, hurl as ulong
let buffer$ = space$(1000)
struct httpget, nread as long
do
let buflen = len(buffer$)
calldll #net, "InternetReadFile", hurl as ulong, _
buffer$ as ptr, buflen as long, httpget as struct, res as long
httpget$ = httpget$ + left$(buffer$, httpget.nread.struct)
loop until httpget.nread.struct = 0
calldll #net, "InternetCloseHandle", hurl as ulong, res as long
calldll #net, "InternetCloseHandle", hnet as ulong, res as long
close #net
end function
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Long strings
« Reply #1 on: Mar 26th, 2016, 7:57pm »

on Mar 26th, 2016, 6:31pm, HugoS wrote:
I have found LBB to be many, many times faster than LB in all respects except when looping through long strings with the word$() function.

Sorry, word$() is slow. The explanation is that there is no direct equivalent in BBC BASIC, so it has to be emulated at run-time - in interpreted BBC BASIC code!

If you've read the How It Works section of the LBB Help file you'll know that LBB is a hybrid translator and emulator. Statements and functions that have a direct equivalent in BBC BASIC are translated at 'compile time' and typically run up to ten times more quickly (possibly even faster). However features that don't have a direct equivalent in BBC BASIC are emulated at run time and typically run at about the same speed as, and sometimes slower than, LB 4.

Could you not do it this way, which is a lot faster than using word$(), and indeed a lot faster than your code running in LB 4.04:

Code:
    test$ = httpget$("http://www.dailymail.co.uk/home/index.html")
    aPos = instr(test$, "<body")
    bPos = instr(test$, "</body>")
    aFile$ = mid$(test$, aPos, bPos - aPos)

    aFile$ = lower$(aFile$)
    toFind$ = "james"
    aCnt = 0
    i = 0
    do
      i = instr(aFile$, toFind$, i+1)
      if i then 
        if trim$(mid$(aFile$, i-1, len(toFind$)+2)) = toFind$ then
          aCnt += 1
        end if
      end if
    loop until i = 0
    notice aCnt
    end
    
'include lb45func.bas
 

The actual counting process (i.e. excluding loading the file from the web) took 0.04 seconds here!!

Richard.
« Last Edit: Mar 26th, 2016, 11:24pm by Richard Russell » User IP Logged

HugoS
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Re: Long strings
« Reply #2 on: Mar 26th, 2016, 9:09pm »

on Mar 26th, 2016, 7:57pm, Richard Russell wrote:
The actual counting process (i.e. excluding loading the file from the web) took 0.04 seconds here!!

Literally a blink of an eye! Much better, thank you Richard.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Long strings
« Reply #3 on: Mar 27th, 2016, 12:19am »

on Mar 26th, 2016, 9:09pm, HugoS wrote:
Literally a blink of an eye! Much better, thank you Richard.

I should perhaps add that if there is no reasonable alternative to word$(), specifying the delimiter - if you are able to - will make it considerably quicker than the default case (when it is having to treat any 'whitespace' as the delimiter).

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls