Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 70ec3427b23fe1c2d782812ca293ede36fb38c19
Ticket: 3069593fffffffffffffffffffffffffffffffff
Performance gap between [string equal] and [string compare]
User & Date: ferrieux on 2010-09-17 22:54:49
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    The "streq" and "strcmp" instructions could benefit from a bit of unification (as suggested by a comment in tclExecute.c).
    
    For example, [string compare] has very efficient special cases for ByteArray and String operands, that [string equal] lacks.
    As a consequence, a naive test of equality on big byte arrays with [string equal] is ~7 times slower than the less obvious [string compare], despite the fact that the latter produces a more elaborate result (three-valued instead of binary):
    
    Source this:
    
      set z [open /dev/zero r]
      fconfigure $z -translation binary
      set b1 [read $z 1000000]
      set b2 [read $z 1000000]
      set y 1
    
    Then interactively:
    
      % time {string compare $b1 $b2} 1000
      301.596 microseconds per iteration
      % time {string compare $b1 $b2} 1000
      299.637 microseconds per iteration
      % time {string compare $b1 $b2} 1000
      298.203 microseconds per iteration
      % ::tcl::unsupported::representation  $b1
      value is a bytearray with a refcount of 2, object pointer at 0x9b55e50, internal representation 0xb69ae010:0x9b56fc0, no string representation.
      % ::tcl::unsupported::representation  $b2
      value is a bytearray with a refcount of 2, object pointer at 0x9b56e58, internal representation 0xb68ac010:0x9b55e50, no string representation.
      % time {string equal $b1 $b2} 1000
      2159.225 microseconds per iteration
      % time {string equal $b1 $b2} 1000
      2128.354 microseconds per iteration
      % time {string equal $b1 $b2} 1000
      2129.929 microseconds per iteration
      % ::tcl::unsupported::representation  $b1
      value is a bytearray with a refcount of 2, object pointer at 0x9b55e50, internal representation 0xb69ae010:0x9b56fc0, no string representation.
      % ::tcl::unsupported::representation  $b2
      value is a bytearray with a refcount of 2, object pointer at 0x9b56e58, internal representation 0xb68ac010:0x9b55e50, no string representation.
    
    
  4. foundin changed to: "None"
  5. is_private changed to: "0"
  6. priority changed to: "7 High"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "ferrieux"
  10. subsystem changed to: "18. Commands M-Z"
  11. title changed to:
    Performance gap between [string equal] and [string compare]
    
  12. type changed to: "Bug"