[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Getting C file handle from port?
From: |
Jeronimo Pellegrini |
Subject: |
Re: [Chicken-users] Getting C file handle from port? |
Date: |
Sun, 21 Mar 2010 00:54:40 -0300 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Sat, Mar 20, 2010 at 04:10:16PM +0100, Peter Bex wrote:
> On Sat, Mar 20, 2010 at 04:01:16PM +0100, Peter Bex wrote:
> > There's even a macro for that: C_port_file.
>
> I added this to the "C interface" documentation. It should appear on
> the wiki shortly.
Thanks Peter and Thomas for your help!
An interesting thing: reading 1000000 floating-point numbers
takes 8.7 seconds using the procedure read, but this:
(define read-flonum
(foreign-lambda* double ((scheme-object port))
"double d; \n
int x = fscanf(C_port_file(port), \" %lf\", &d); \n
if (x != 1) {
puts(\"Error: couldn't read floating-point number\");
exit(-1);
} else C_return(d);\n "))
is 10x faster (0.85 s). It's roughly as fast as a pure C
implementation I used for comparison.
It's a quick hack, but illustrates what I'd like to do: read
a large matrix (much larger than the one in this example) quickly
(I don't want the safety and type checks for this procedure;
the matrix may need to be read several times from several different
files).
Again, thanks a lot guys!
J.