dict versus array of integers
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

dict versus array of integers

From: Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Date: Tue Dec 06 2005 - 13:14:14 CET

This weekend I played around with some numbertheory,
counting all possible (finitely limited) results
of an [expr {... % $n}]

I first did it (out of habit) with arrays:
proc count {n} {
  some_loop i { set c([expr {... % $n}]) 1 }
  array size c
}
For some data it took about 700000 microseconds.

I then changed it to:
proc count {n} {
  some_loop i { dict set c [expr {... % $n}] 1 }
  dict size $c
}
Which expectedly gave the same result, but was
(not horribly, but noticeably) slower: about 800000 microseconds.

Are dicts generally slower for this particular task, or
is my code triggering some object-string-conversion
corner case (with a numeric result being used as key)
that for some other reasons does not hit array ?

PS:
 In my context I can safely assume that the loop
 always runs at least once, so there was no direct
 need to ensure existence of "c" beforehand.
Received on Sun Dec 11 13:53:49 2005