From sfalcon at fhcrc.org  Thu Sep 28 04:53:34 2006
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Wed, 27 Sep 2006 19:53:34 -0700
Subject: [Rd] eval(SEXP fn,SEXP rho) in C++ code
In-Reply-To: <20060928022930.39335.qmail@web32709.mail.mud.yahoo.com>
	(Patricia Bautista's message of "Wed,
	27 Sep 2006 21:29:30 -0500 (CDT)")
References: <20060928022930.39335.qmail@web32709.mail.mud.yahoo.com>
Message-ID: <m2lko48zwx.fsf@ziti.local>

Patricia Bautista <pbautist2 at yahoo.com.mx> writes:

> Hi r-devel, 
>
> I am working on a R extension. I am writing the
> function in C++, and in my function it is required a R
> function object from the user. This R function object
> will be evaluated thousand of times in my C++ code. I
> generated the shared library and I loaded it on R. I
> did several experiments in order to compare the speed
> of my compiled code vs the speed of the equivalent
> interpreted code. I was surprise!, the better was  the
> interpreted code!. Then, I ask myself: What is the
> benefit of compiled code??.  I think my problem is in
> using the function "eval(SEXP f, SEXP rho)" because it
> takes time!. Am I right?. Then, can someone tell me
> what  the benefit of using compiled code is?, or can
> someone give me a reference to look into?.

If you use eval in C you are doing effectively the same thing as at
the interpreter (R) level.

The benefit of doing computations in C comes from making direct calls
to R's C API, avoiding duplication (copy of R objects), etc.

+ seth




[Rd] eval(SEXP fn,SEXP rho) in C++ code
Seth Falcon