It is, but I created a form that forces it to not be inlined, and that 
still runs in just 30 ms.

On Tuesday, January 20, 2015 at 4:57:00 PM UTC-6, Jeff Bezanson wrote:
>
> Oh, I should also mention that the version that calls goo(foo()) takes 
> so little time because the entire loop is probably optimized out. 
>
> On Tue, Jan 20, 2015 at 5:54 PM, Jeff Bezanson <jeff.b...@gmail.com 
> <javascript:>> wrote: 
> > Here is a hack that basically works by escaping through the C type 
> system: 
> > 
> > ``` 
> > immutable CFunction{R,A} 
> >     f 
> >     p::Ptr{Void} 
> >     CFunction(f) = new(f, cfunction(f, R, (A,))) 
> > end 
> > 
> > call{R,A}(f::CFunction{R,A}, x) = ccall(f.p, R, (A,), x) 
> > 
> > foo(x::Float64) = 0.0 
> > goo(x::Float64) = x 
> > 
> > function test1() 
> >     for i=1:100000000 
> >         f = foo 
> >         r = f(1.0) 
> >         goo(r) 
> >     end 
> > end 
> > 
> > function test2() 
> >     f = CFunction{Float64,Float64}(foo) 
> >     for i=1:100000000 
> >         r = f(1.0) 
> >         goo(r) 
> >     end 
> > end 
> > ``` 
> > 
> > I added an argument to `foo` to increase the generality somewhat. 
> > test1() is the original test case. test2() is the new version. The 
> > CFunction object needs to be constructed outside the loop, but this 
> > can be stored in a data structure and reused anywhere. 
> > 
> > -Jeff 
> > 
> > 
> > On Tue, Jan 20, 2015 at 4:34 PM, Ivar Nesje <iva...@gmail.com 
> <javascript:>> wrote: 
> >> Originally posted at https://github.com/JuliaLang/julia/issues/9863 
>

-- 


Please click here 
<http://www.e-disclaimer.com/conning/AD21D06B4CC99D2B4F24BA73FB4EED83.htm> for 
important information regarding this e-mail communication.

Reply via email to