Dear listmembers,
I wrote a function in octave that basically does what I want it to. However, I
am facing speed issues.
My function contains a loop to write it's results into a file - formatted ...
please see the following example-code:
tic
j=linspace(0,99999,100000);
outfile=fopen("/home/fred/work/Software/octave/test/Spektrum.dat", "w");
fprintf (outfile, "#\n# Nr. Spektrum, Zeitfunktion Eingangssignal\n#\n");
for i=1:100000
fprintf(outfile, "%d %12.10f %12.10f %12.10f\n", j(i), s(i), B(i), A(i));
endfor
toc
Please consider the arrays to be filled as intended. The elapsed time is said
to be 4.2 seconds. As you might see from this, I grew up programming "C"
language :-)
Now I played a little with fprintf, bound to fail, however this:
tic
j=linspace(0,99999,100000);
outfile=fopen("/home/fred/work/Software/octave/test/Spektrum.dat", "w");
fprintf (outfile, "#\n# Nr. Spektrum, Zeitfunktion Eingangssignal\n#\n");
fprintf(outfile, "%d %12.10f %12.10f %12.10f\n", j, s, B, A);
toc
doesn't do the right thing, as the arrays are treated one after the other,
leading to a strange looking output file, however the elapsed time goes down
to 0.38s or 1/10th of the time used for the "for" loop. All data I want to
write to the file are in there, but you know, the order of the data is not
what I hoped it to be.
I am not a speed junky, but a factor of 10 is something significant IMHO. This
for loop is the element in my program lasting longer than anything else. Does
anybody know a more efficient way to write my data to the output file without
such a huge loss in performance?
Many thanks for any suggestion in advance,
take care
Dieter Jurzitza