I don't think the anonymous y -> 1/g(y) and the nested function invg(y) = 1//g(y) are any different in terms of performance. They both form closures over local variables and they should both be faster under 0.5.
I did run your code under 0.5dev and it was slower, but I think they're still fixing a variety of performance issues. I don't know much about it though. On Saturday, June 18, 2016 at 10:25:11 AM UTC-4, Marius Millea wrote: > > Ahh sorry, forget the 2x slower thing, I had accidentally changed > something else. Both the anonymous y->1/g(y) and invg(y) give essentially > the exact same run time. > > There are a number of 1's and 0's, but AFAICT they shouldn't cause any > type instabilities, if the input variable y or x is a Float64, the output > should always be Float64 also. In any case I did check switching them to 1. > and 0.'s but that also has no effect. > > Marius > > > > > On Saturday, June 18, 2016 at 4:08:59 PM UTC+2, Eric Forgy wrote: >> >> Try code_warntype. I'm guessing you have some type instabilities, e.g. I >> see some 1's and 0's, where it might be better to use 1.0 and 0.0. Not sure >> :) >> >> On Saturday, June 18, 2016 at 9:48:29 PM UTC+8, Marius Millea wrote: >>> >>> Thanks, yea, I had read that too and at some point checked if it >>> mattered and it didn't seem to which wasn't entirely surprising since its >>> on the outer loop. >>> >>> But I just checked again given your comment and on Julia 0.4.5 it seems >>> to actually be 2x slower if I switch it to this: >>> >>> function f(x) >>> invg(y) = 1/g(y) >>> quadgk(invg,0,x)[1] # <=== outer integral >>> end >>> >>> Odd... >>> >>> >>> On Saturday, June 18, 2016 at 3:41:37 PM UTC+2, Eric Forgy wrote: >>>> >>>> Which version of Julia are you using? One thing that stands out is the >>>> anonymous function y->1/g(y) being passed as an argument to quadgk. I'm >>>> not >>>> an expert, but I've heard this is slow in v0.4 and below, but should be >>>> fast in v0.5. Just a though. >>>> >>>> On Saturday, June 18, 2016 at 8:53:57 PM UTC+8, Marius Millea wrote: >>>>> >>>>> Hi all, I'm sort of just starting out with Julia, I'm trying to get >>>>> gauge of how fast I can make some code of which I have Cython and Fortran >>>>> versions to see if I should continue down the path of converting more or >>>>> my >>>>> stuff to Julia (which in general I'd very much like to, if I can get it >>>>> fast enough). I thought maybe I'd post the code in question here to see >>>>> if >>>>> I could get any tips. I've stripped down the original thing to what I >>>>> think >>>>> are the important parts, a nested integration with an inner function >>>>> closure and some global variables. >>>>> >>>>> module test >>>>> >>>>> const a = 1. >>>>> >>>>> function f(x) >>>>> quadgk(y->1/g(y),0,x)[1] # <=== outer integral >>>>> end >>>>> >>>>> function g(y) >>>>> integrand(x) = x^2*sqrt(x^2*y^2+a)/(exp(sqrt(x^2+y^2))+a) >>>>> quadgk(integrand,0,Inf)[1] # <=== inner integral >>>>> end >>>>> >>>>> end >>>>> >>>>> >>>>> > @timeit test.f(1.) >>>>> 100 loops, best of 3: 3.10 ms per loop >>>>> >>>>> >>>>> >>>>> >>>>> Does anyone have any tips that squeezes a little more out of this >>>>> code? I have run ProfileView on it, and although I'm not sure I fully >>>>> understand how to read its output, I think it's saying the majority of >>>>> runtime is spent in quadgk itself. So perhaps I should look into using a >>>>> different integration library? >>>>> >>>>> Thanks for any help. >>>>> >>>>>