Yes. The Tally2 function, runs at 0.020 microseconds per byte on my PC. A little Assembly code would improve it further, by holding some of the pointers in registers, but it would not make a huge difference. I think small programs end up running inside the CPU core memory, which has fast access.
Charles
PS: Try this version. I replaced the
if constructs with a
case block, and it runs quite a bit faster. I get 11 ns per byte.
function tally2(string main,delim, sys *dp, max) as sys
'======================================================
sys a,p,le,ld,tal,ascd
le=len main
ld=len delim
if ld=0 or le= 0 then exit function 'NULL STRINGS
ascd=asc delim
'
p=strptr main 'string pointer
byte *b 'pointered byte
@b=p 'map to main string
do
select b
case 0 : exit do
case 39 : 'SKIP QUOTE
do
@b++
if b=39 or a<=le then exit do
end do
@b++
continue do
case ascd
a=@b-p+1
if a=instr(a,main,delim) then 'CONFIRM MATCH
if tal>=max then exit do 'ARRAY LIMIT EXCEEDED
tal++
dp[tal]=a
@b+=ld
continue do
end if
end select
@b++
end do
return tal
end function