Re: [julia-dev] JIT performance with passed function handles

305 views
Skip to first unread message

Jeff Bezanson

unread,
Apr 4, 2013, 12:46:07 AM4/4/13
to juli...@googlegroups.com
Yes, making the function-argument version just as fast is high on my to-do list.

On Wed, Apr 3, 2013 at 7:24 PM, Colm Ryan <co...@colmryan.org> wrote:
> I'm writing a generic cumulative reduce function and the performance seems
> to be about ten time slower than the built-in ones, for example cumsum. It
> seems to boil down to the JIT not being able to accelerate a passed
> function. The following example which compares passing and not passing a
> function handle sums up the issue:
>
> function reducetest(op::Function, v::AbstractVector)
> n = length(v)
> out = similar(v, typeof((zero(eltype(v)))))
> out[1] = v[1]
> for ct = 2:n
> out[ct] = op(v[ct],out[ct-1])
> end
> return out
> end
>
> function reducetest(v::AbstractVector)
> n = length(v)
> out = similar(v, typeof((zero(eltype(v)))))
> out[1] = v[1]
> for ct = 2:n
> out[ct] = +(v[ct],out[ct-1])
> end
> return out
> end
>
> function speedtest(arraySize)
> junk = randn(arraySize)
> print("\nBuiltin cumsum:\n")
> @time (for ct = 1:100, out = cumsum(junk); end)
> print("\nPasssing function:\n")
> @time (for ct = 1:100, out = reducetest(+, junk); end)
> print("\nNot passsing function:\n")
> @time (for ct = 1:100, out = reducetest(junk); end)
>
>
> end
>
>
> which gives:
>
> julia>speedtest(100000)
>
> Builtin cumsum:
> elapsed time: 0.082851409 seconds
> Passsing function:
> elapsed time: 1.065588846 seconds
> Not passsing function:
> elapsed time: 0.069623861 seconds
>
>
> I also noticed the reduce function check the passed function and specializes
> for the addition and multiplication operators, presumably for the same
> performance reasons. I was curious if there is any hope of making the
> general passed function version just as fast?
>
> --Colm
>
>

Ben Arthur

unread,
Apr 3, 2015, 1:30:12 PM4/3/15
to juli...@googlegroups.com
umm, 2 years later, function handles are still quite slow.  is there a way to speed them up?  thanks.

Isaiah Norton

unread,
Apr 3, 2015, 1:33:55 PM4/3/15
to juli...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages