Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 11e8d22266ca1ad8cecb1b3f6430548ce8dcc35e
Ticket: 219228ffffffffffffffffffffffffffffffffff
improve speed of read command
User & Date: nobody on 2000-10-26 05:03:51
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 4206 RFE
    Version: 8.2.3
    SubmitDate: '2000-02-22'
    LastModified: '2000-03-30'
    Severity: LOW
    Status: Assigned
    Submitter: techsupp
    ChangedBy: hobbs
    OS: Solaris
    OSVersion: SunOS 5.7
    Machine: Ultra Sparc, 128MB of RAM, Single Processor.
    FixedDate: '2000-10-25'
    ClosedDate: '2000-10-25'
    
    
    Name:
    David Whittle
    
    Extensions:
    Sybtcl-2.5 (although it was not loaded for the test).
    
    CustomShell:
    None.
    
    ReproducibleScript:
    # The file represented by "test.file" should be a binary file
    # with 2+ million records, where a record is defined as 42 bytes.
    set fp [open test.file r]
    set i 0
    set time [clock seconds]
    while {[read $fp 42] != 0} {
        if ![expr 50000 % $i] {
            set now [clock seconds]
            puts "[expr $now - $time] secs, $i recs, [expr 50000 / ($now - $time)] recs per sec"
            set time $now
        }
    }
    close $fp
    
    ObservedBehavior:
    The issue that I have found is that running the above script (which is essentially only doing a read) takes ~8 seconds to process 50000 "records". When we compared this against a similar Perl script, Perl out did Tcl by a few orders of magnitude (Perl ran through 200000 in ~1 second).
    I looked at the code for the read command and it appears to me that the issue lies in the entended work with the channel code as well as how it appears to attempt to process each byte, even if no conversion is required.
    I also tried testing this in 8.1.1 (The above script wouldn't work in 8.0 and below (i'm guessing due to the binary data in the file)) which ran a bit faster (5 seconds for 50,000 records) and 8.3 which ran about the same speed as 8.2.3.
    
    DesiredBehavior:
    I would expect unless something has been specified differently in the fconfigure command that it would bubble down to a simple fread command for increased performance on the reads.
    
    
    
    I would expect a noticeable speedup if the standard programming
    paradigms were followed.  This should be:
    
    proc process {file} {
      set fp [open $file r]
      set i 0
      set time [clock seconds]
      while {[read $fp 42] != 0} {
        if {!(50000 % $i)} {
            set now [clock seconds]
            puts "[expr {$now - $time}] secs, $i recs, [expr {50000 / ($now - $time)}] recs per sec"
            set time $now
        }
      }
      close $fp
    }
    process test.file
    
    That needs to be tested first, before we evaluate the I/O (which
    could likely be improved).  Of course, bulk reads with range
    fetches would then be much better. 
    -- 02/22/2000 hobbs
    
    
    
  4. foundin changed to: "final: 8.2.3"
  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: "37. File System"
  10. title changed to: "improve speed of read command"
  11. type changed to: "RFE"