Performance
Fred Gansevles
gansevle at cs.utwente.nl
Tue Jul 4 06:14:08 EDT 2000
In article <39619175.5F8B503D at proceryon.at>,
Horst Gassner <horst at proceryon.at> wrote:
> Hi all!
>
> I have implemented a tree view with special items (the base for this
> work was the TreeWidget from IDLE).
>
> The performance is not the best and therefore I ran the profiler
today.
> The following function is one of the slower ones and I would be happy
if
> there are any possibilties to speed this thing up.
>
> subItems = {}
> if s.__subList[level] :
> for key in s.__subList[level].keys ():
> # root level is special case!
> # get all sublevels without recognizing id of sublevel
> if level==0 or string.find(key, id) == 0 :
> subItems[key] = s.__subList[level][key]
>
> The functions looks for all subitems for a given level and a given id.
> For each level I have pre-built a list that I have just to go through
> the items of the given level.
>
You can speed things up by putting the special case outside the loop
Another speedup is: use slices instead of string.find since you only
match the first part of the key
<untestded_code>
subItems={}
if s.__subList[level]:
if level == 0:
# root level is special case
subItems = s.__subList[level].copy()
else:
id_len = len(id)
for key in s.__subList[level].keys ():
if key[:id_len] == id:
subItems[key] = s.__subList[level][key]
</untested_code>
This might improve things abot 5-10% depending on how often string.find
would fail on finding the id.
> Thanx in advance
> Horst
>
--
-----------------------------------------------------------------------
---- Linux/Windows-NT/IntraNetware Administrator ----
-- Whenever it sounds simple, I've probably missed something! ... Me --
-----------------------------------------------------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list