Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nalimilan
Last active November 19, 2016 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nalimilan/e97e6561c7006b4ce2dba0f85519a2a8 to your computer and use it in GitHub Desktop.
Save nalimilan/e97e6561c7006b4ce2dba0f85519a2a8 to your computer and use it in GitHub Desktop.
broadcast_fuse(types::Type, f) = f
broadcast_fuse(types::Type, f, fs...) = x -> f(broadcast_fuse(types, fs...)(x))
a(x) = x+1
b(x) = x*x
f1(x) = broadcast_fuse(Array, a, b)(x) # Needed so that the compiler treats anonymous function as const
@code_warntype f1(1)
@code_native f1(1)
f2(x) = a(b(x))
@code_warntype f2(1)
@code_native f2(1)
f3(x) = broadcast(f2, x)
@code_warntype f3(1)
@code_native f3(1)
using BenchmarkTools
@benchmark f1(1)
@benchmark f2(1)
@benchmark f3(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment