Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-04-21
02:48 • Ticket [218181ffff] Array performance degrades as array size increases statu... artifact: a6fc9fd47c user: dgp
2000-10-26
08:16 • Closed ticket [218181ffff]. artifact: 8b8b2fe84c user: welch
00:54 • New ticket [218181ffff]. artifact: 6d8c8f8d04 user: nobody

Array performance degrades as array size increases

Closed / Fixed218181ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:54:13
OriginalBugID: 2332 Bug
Version: 8.0.5
SubmitDate: '1999-07-06'
LastModified: '1999-08-05'
Severity: MED
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
OS: HP-UX
OSVersion: 10.20
Machine: Other
FixedDate: '2000-10-25'
ClosedDate: '1999-08-05'


Name:
Ted Romer

ReproducibleScript:
Script "slow-array.tcl"
    
    # demonstrate slowness of tcl arrays as the array gets big
    
    #
    # Build an array with 2^exponent entries, and return
    # the average of 10 array accesses (measured in "clicks")
    #
    proc onepoint {exponent} {
        global g_val
    
        #
        # Build the array
        #
        set limit [expr {int(pow(2,$exponent))}]
        for { set i 0 } {$i < $limit} {incr i} {
            set arr($i) $i
        }
    
        #
        # Some arbitrary members of the array; we mod by the
        # array size to make sure they are legal
        #
        set samples [list 0 31 63 127 255 511 1023 2047 4095 8191]
        foreach sample $samples {
            lappend indices [expr $sample % $limit]
        }
    
        #
        # So how long does it take to look up those indices?
        #
        set start [clock clicks]
        foreach index $indices {
            set g_val $arr($index)
        }
        set end [clock clicks]
        
        #
        # Return the average access time.
        #
        return [expr { ($end-$start+0.0)/[llength $indices] }]
    }
    
    #
    # Generate a table of (array size, avg access time in microseconds (on
    HP-UX))
    #
    proc main {argc argv} {
        puts "Array size   Access time (us)"
        for { set exponent 0 } {$exponent <= 16} {incr exponent} {
            set limit [expr {int(pow(2,$exponent))}]
            puts [format "%10d %18.1f" $limit [onepoint $exponent]]
            flush stdout
        }
    }
    
    main $argc $argv
    
    Invocation:
    tclsh slow-array.tcl

ObservedBehavior:
Output:
    
    Array size   Access time (us)
             1               17.9
             2               15.3
             4               15.0
             8               14.4
            16               14.3
            32               14.6
            64               15.1
           128               15.1
           256               16.1
           512               17.6
          1024               21.4
          2048               26.8
          4096               56.3
          8192              115.8
         16384              121.0
         32768              562.6
         65536             1842.7
    
    i.e. in an array with 65536 elements, looking up a *single* element
    takes on average nearly 0.2 seconds!

DesiredBehavior:
I expect hash tables to have roughly constant access time, independent
    of size, until the amount of space dedicated to array storage is at 
    least a few megabytes.



Discussion on the newsgroup showed that this seemed to be the using
hitting some file system resource limit (swap, or such). 
-- 08/05/1999 hobbs
welch Closed ticket [218181ffff]. [History diff]2000-10-26 08:16:55
dgp Ticket [218181ffff]: 3 changes [History diff]2001-04-21 02:48:37
Log in (anonymous is fine) to add a comment.