Subject: Improvements to Tcl arrays. - DN [1]
Paul Duffin <pduffin@mailserver.hursley.ibm.com> - 22 Feb 1999 - comp.lang.tcl
A while ago I proposed that Tcl arrays should use Tcl_Obj's for their
keys instead of C strings. I have just done some tests to see what
effect they have on both memory usage and speed and here are the
results.
To do a comparison I implemented a command called objArray. It
implements the following commands.
o set
Same as [array set]
o get
Same as [array get] except no pattern matching.
o names
Same as [array names] except no pattern matching.
I did some tests with different size keys and arrays and came up with
the following stats. Note the obj array does not have the overhead of
variable lookup but this is minimal compared to the actual array
processing. The meaning of the different stats is as follows.
o bytes The increase in allocated memory caused by the action.
o mallocs The number of malloc calls caused by the action
o frees The number of free call caused by the action
o us The time in microseconds to complete the action (timed
over 10 runs).
Tcl array Obj array
Large array, small keys
-----------------------
Setting 10 arrays bytes 984637 362203
with 1600 keys 8 mallocs 32262 16242
characters long frees 214 184
us 44001 24532
Getting contents of bytes 805413 246824
the 10 arrays and mallocs 32373 382
storing in 10 frees 315 324
variables us 55305 12105
Getting keys of bytes 682334 124193
the 10 arrays and mallocs 32362 374
storing in 10 frees 304 315
variables us 27664 7384
Small array, large keys
-----------------------
Setting 10 arrays bytes 665117 5083
with 32 keys 4096 mallocs 552 372
characters long frees 184 154
us 12090 4969
Getting contents of bytes 662533 2984
the 10 arrays and mallocs 623 312
storing in 10 frees 245 254
variables us 17390 452
Getting keys of bytes 661374 2273
the 10 arrays and mallocs 612 304
storing in 10 frees 234 245
variables us 9230 1098
As you can see making the Tcl array use Tcl_Obj's greatly increases the
scaleability of Tcl.
--
Paul Duffin
DT/6000 Development Email: pduffin@hursley.ibm.com
IBM UK Laboratories Ltd., Hursley Park nr. Winchester
Internal: 7-246880 International: +44 1962-816880
Last modified
1999-09-27
1999-09-27
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
