[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Slowness in function 'open'
From: |
Dmitri A. Sergatskov |
Subject: |
Re: Slowness in function 'open' |
Date: |
Thu, 21 Jun 2007 17:44:13 -0500 |
Another option. You can pipe your file through text to binary
converter written in C like e.g.[1]:
/* begin */
#include <stdio.h>
int
main(void)
{
double a;
while(EOF != fscanf(stdin, "%lf", &a)){
fwrite(&a, sizeof(double), 1, stdout);
}
return 0;
}
/* end */
gcc -Wall -O2 readit.c -o readit
time ./readit < xxx.dat > zzz.bin
real 0m1.702s
user 0m1.624s
sys 0m0.076s
And than in octave (since the file is not in octave format,
you still need to do a low-level file i/o)
octave:6> fh=fopen("zzz.bin");
octave:7> tic; [a, count] = fread(fh, inf, 'double'); toc
Elapsed time is 0.780479 seconds.
octave:8> count/5
ans = 512000
This is 1.7 + 0.78 ~2.5 sec total time which is ~2.5 times faster
on my computer than reading the original ASCII file (6.6 sec).
Sincerely,
Dmitri.
p.s. [1] perhaps, the program can be improved by doing some buffering
on i/o, but I am too lazy to do it myself :)
--
Re: Slowness in function 'open', Dmitri A. Sergatskov, 2007/06/21