Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ba1ff952999791a8e2861dc011f9fcc67e466d50
Ticket: 1366484fffffffffffffffffffffffffffffffff
patch: speed up lsort (follow on to 1360413)
User & Date: afredd on 2006-01-12 02:10:05
Changes

  1. icomment:
    Logged In: YES 
    user_id=1386588
    
    OK as promised :-)
    Here's a zip file with a 8.5a3 tclCmdIL.c with Perl's
    merge sort in. I've included some timing results
    and a test script. NB. the sort is documented as being
    stable.
    
    *WARNING* this is not a patch (yeah - i know this probably
    isn't the best place for it :-) but might be of interest
    to someone.
    
    So is it faster? .... Well, if the list has any
    existing order, then yes. For rand()om data using a quick
    comparator (ie. not -command!) then no.
    It can be massively faster; it is usually not too far off.
    
    Overall. I'm inclined not to go any further with this.
    The perl sort uses slightly more memory, and is slower
    for [lsort -integer $a_random_list_of_ints].
    Not much point swapping the sort alg. if it is slower
    in a potentially likely situation.
    
    NB. while i'm here (and apologies for being OT)...
    lsort could use a -numeric option
    (or -bignum, or ...) that is equivalent to:
    
    proc num_cmp {a b} {
     if {$a > $b} { return 1 }
     if {$a < $b} { return -1 }
     return 0
    }
    lsort -command num_cmp $num_list
    
    as currently there is no builtin way to sort
    either wides or the new big nums if they are
    too big. Consider:
    
    set l [list \
     [expr wide(100000000000000002)] \
     [expr wide(100000000000000001)] \
     [expr wide(100000000000000003)] \
    ]
    
    puts [lsort -real $l] # wrong result
    puts [lsort -integer $l] # integer too big
    
    I feel a TIP coming on :-)
    
    
    
  2. login: "afredd"
  3. mimetype: "text/plain"
  4. username: "afredd"