LB Booster
Programming >> BASIC code examples >> python dict in JB LB and LBB
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1469612989

python dict in JB LB and LBB
Post by bluatigro on Jul 27th, 2016, 09:49am

Code:
global key$ , value$ , cut$ , lenght
lenght = 20
cut$ = "|"
call store "i" , "mi"
call store "you" , "vi"
call store "he" , "li"
call store "she" , "si"
call store "greating" , "saluton"
call store "it" , "gi"
print dict$( "i" )
print dict$( "you" )
print dict$( "he" )
print dict$( "q" )
print dict$( "she" )
print dict$( "greating" )
print dict$( "it" )
end
sub store k$ , v$
  if instr( key$ , pad$( k$ ) ) then exit sub
  key$ = key$ + pad$( k$ )
  value$ = value$ + v$ + cut$
end sub
function dict$( k$ )
  p = instr( key$ , pad$( k$ ) )
  if p = 0 then
    uit$ = "NOT THERE"
  else
    p = ( p - 1 ) / lenght + 1
    uit$ = word$( value$ , p , cut$ )
  end if
  dict$ = uit$
end function
function pad$( a$ )
  pad$ = left$( a$ + space$( lenght ) , lenght )
end function
 

Re: python dict in JB LB and LBB
Post by Richard Russell on Jul 27th, 2016, 2:10pm

This is the sort of program that can benefit from LBB's speed. I modified it to time 1000 sets of dictionary lookups as follows:

Code:
start = time$("ms")
for i = 1 to 1000
  d1$ = dict$( "i" )
  d2$ = dict$( "you" )
  d3$ = dict$( "he" )
  d4$ = dict$( "q" )
  d5$ = dict$( "she" )
  d6$ = dict$( "greating" )
  d7$ = dict$( "it" )
next i
finish = time$("ms")
print finish - start; " ms" 

Results on this relatively slow laptop:

LBB 3.05: 250 ms
LB 4.04/JB 1.01: 1750 ms

So LBB is about 7 times faster in this case.

Richard.