Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 290f2ffff583884440b8b54d37f4f9ef98a6d618
Ticket: 32c5740a4d3e86b1973915d92f07d5aee6104a14
Undesirable [lappend] performance as LIST_MAX is reached
User & Date: dgp on 2015-11-19 18:13:03
Changes

  1. icomment:
    
    Next thing I notice is the anti-idiom
    
    if {[expr {...}]}...
    
    The condition argument of an [if] command
    is already an expression.  There's no need
    to use [expr] to make it one.
    
    It is also strange to make use of fmod() to
    do integer modulus in light of the % operator.
    
    Better code looks like:
    
    if {$count % 100000000 == 0} {...
    
    Somewhat surprisingly the use of [expr] makes
    little difference. Bytecode compilation gets
    to essentially the same instructions. Avoiding
    the floating point conversion tax helps some.
    
    A few more tweaks leads to:
    
    set my_list {}
    set count 0
    set t0 [ clock seconds ]
    # Create a list with a billion elements
    while {$count < 1000000000} {
           lappend my_list A
           set count [llength $my_list]
           if { $count % 100000000 == 0.0 } {
              # Show progress every 100 million elements
              set tnow [ clock seconds ]
              puts "elapsed time: [ expr { $tnow - $t0 } ] seconds"
              puts $count
           } elseif { $count > 402600000 } {
              # Show progress more incrementally
              if { $count % 1000 == 0.0 } {
                  set tnow [ clock seconds ]
                  puts "elapsed time: [ expr { $tnow - $t0 } ] seconds"
                  puts $count
              }
           }
    }
    
  2. login: "dgp"
  3. mimetype: "text/plain"