Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6d8c8f8d0431c8a30c28b6f78690687dda0c9b9c
Ticket: 218181ffffffffffffffffffffffffffffffffff
Array performance degrades as array size increases
User & Date: nobody on 2000-10-26 00:54:13
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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
    
  4. foundin changed to: "final: 8.0.5"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to: "Array performance degrades as array size increases"
  11. type changed to: "Bug"