[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Is fprintf slow?
From: |
Ted Harding |
Subject: |
Is fprintf slow? |
Date: |
Sun, 26 Mar 1995 13:09:36 +0200 (BST) |
Is fprintf in Octave intrinsically slow? I use it to create datafiles
as an interface to Plotmtv, and it seems to run very slow. For instance,
a datafile of 190214 bytes took 433 seconds to write to disk
(439 bytes/second). This strikes me as unexpectedly slow. (CPU is
a 386-DX/25MHz).
Here is the nub of the script which I use to write a matrix X with R rows
and C columns of numbers to an ASCII file FIL in format FMT
with space-separated numbers:
S=size(X); R=S(1); C=S(2);
fopen(FIL,"a");
for i=1:R
for j=1:C
fprintf(FIL,FMT,X(i,j)), fprintf(FIL,' '), end, fprintf(FIL,'\n')
end
FMT is a string (like "%8.5g") for a single number. Maybe there is
some point in initially programming the build-up of a more complex
format string to cope with one entire row of X at a time (fprintf
needs a format specifier for each separate number, and the size of X
is not known beforehand). But any advice or comment would be welcome.
The above timing was for a 10,000 x 2 matrix with FMT="%8.5g", so
I can't see this idea speeding things up by a factor of more than 2-3.
I'm more interested in factors of the order of 50-100!
Here is comparison with timings for "save" in the various builtin formats:
written as above: 433 secs
save -text: 48.6 secs
save -binary: 0.15 secs
save -mat-binary: 0.11 secs
Maybe I could do a binary dump and use a custom C program to write the
ASCII file. In that case where can I find out Octave's binary format?
(and/or Matlab's ... ?).
(However, this would be very inconvenient for the present purpose,
since a lot also depends on interpolating plot-control commands
into the data: this would become very tricky using an external
program to write the Plotmtv data file.)
Ted. (address@hidden)
- Is fprintf slow?,
Ted Harding <=