Author |
Topic: Long strings (Read 531 times) |
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
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.
|
|
|
|
HugoS
New Member
member is offline


Posts: 5
|
 |
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.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
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.
|
|
Logged
|
|
|
|
|