help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: speed of fread in octave


From: David Bateman
Subject: Re: speed of fread in octave
Date: Wed, 14 Jun 2006 10:21:06 +0200
User-agent: Mozilla Thunderbird 1.0.6-7.6.20060mdk (X11/20050322)

John W. Eaton wrote:

>On 13-Jun-2006, Peter Cloetens wrote:
>
>| We are using version 2.1.71.
>| The platform is Linux Suse 8.2 , Suse 9.0 or RHEL4 on Xeon or Opteron  
>| CPU's.
>| I didn't notice a significant difference between the different OS /  
>| cpu combinations.
>| 
>| We are calling fread inside functions and scripts, but even in its  
>| simplest form the speed difference is obvious.
>| I would not call it a bug, but a performance issue.
>| 
>| For example:
>| in octave:
>| address@hidden:PZ> fid=fopen('ref0000_0000.edf','rb');
>| address@hidden:PZ> readedfheader(fid);
>| address@hidden:PZ> tic;fread(fid,1748*2048,'uint16');toc
>| ans = 0.53232
>| 
>| in matlab:
>|  >> fid=fopen('ref0001_0000.edf','rb');
>|  >> readedfheader(fid);
>|  >> tic;fread(fid,1748*2048,'uint16');toc
>| Elapsed time is 0.049493 seconds.
>
>OK, I took a quick look at this.  The code that handles reading and
>data type conversion is the do_read function in src/oct-stream.cc.  It
>is not optimized for the case of SKIP=0, so it calls an istream::read
>function for each value.  Optimizing the SKIP=0 case would make a nice
>project for someone who wants to help improve Octave.
>
>Thanks,
>
>  
>
Maybe you should give some more information so that someone who want to
do the modification can understand its complexity.

At the moment the code in do_read has a structure in pseudo-code like

resize the return matrix to the right size
for (;;) {
   if (is) {
      read a value
      if (skip) skip values in file
      if (swap or float_conversion) do the byte swapping and format
conversion
      resize return matrix if necessary
      insert read value into return matrix
      do is.eof() or done then break
   }
}

and the change would be to make the above become something like

resize the return matrix to the right size
if (!skip) {
   get fortran_vec of return matrix cast as char
   read all required values from file
   if (swap or float_conversion) do the byte swapping and format conversion
   if didn't read necessary number of values resize return matrix
} else {
   as above
}

it should be as you say a fairly easy change to make as all of the
support code is already in place

}


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

[Prev in Thread] Current Thread [Next in Thread]