Re: map vs append

new topic     » goto parent     » topic index » view thread      » older message » newer message

Below, I've shown the actual code that got changed. I stripped most of the guts of the code to show just the changed lines, but kept a few other lines for some context.

sequence 
-- initially, the 'map' was kept in the standard two-element sequence 
-- where an element in sequence 1 was related to the same element in sequence 2... the poor man's map smile 
--	logs = {{},{}}   
 
-- now I keep it in a map 
map mLogs = map:new() 
 
-- the following loop would run over 4600 times (currently); this number grows on a daily basis 
-- it uses file data in the years[] sequence 
for t=1 to yCount do 
-- i was growing the original sequence with append(), as below 
-- 		logs[1] = append(logs[1],years[t][D_NAME][1..10]) 
-- 		logs[2] = append(logs[2],match( ".GOT", upper( years[t][D_NAME] ) ) > 0 ) 
 
-- now i'm using a map 
	map:put( mLogs, years[t][D_NAME][1..10], match( ".GOT", upper( years[t][D_NAME] ) ) > 0 ) 
end for 
 
for t=1 to length(files) do 
	for x=1 to length(TEMP) do 
		text = split( TEMP[x], "\t" ) 
		if length(text) > 2 then 
 
-- now, instead of find()ing... 
-- 			i = find( text[CODE], logs[1] ) 
-- I use map:has() 
			i = map:has( mLogs, text[CODE] ) 
			 
			if i > 0 then 
-- and instead of a sequence query 
-- 				if logs[2][i] then 
-- I use a map:get() 
				if map:get( mLogs, text[CODE] ) then 
				end if 
			end if 
		end if 
	end for 
end for 

There's no way to parse what I'm doing with the data from this snipped example, but these few changes led to a significant speed-up: from 15-20 seconds to less than 2 seconds.

The speed-up, no doubt, comes from the building of the 4,600+-element sequence/map using map:put(), not the query/get changes.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu