Skip to content

Instantly share code, notes, and snippets.

@simonbyrne
Created July 28, 2014 13:32
Show Gist options
  • Save simonbyrne/734dcacde1f107397b3b to your computer and use it in GitHub Desktop.
Save simonbyrne/734dcacde1f107397b3b to your computer and use it in GitHub Desktop.
function sincos(x)
psin = Cdouble[0]; pcos = Cdouble[0]
ccall(:sincos, Void, (Cdouble, Ptr{Cdouble}, Ptr{Cdouble}), x, psin, pcos)
psin[1], pcos[1]
end
function foo(X)
ta = 0.0
tb = 0.0
for x in X
a = sin(x)
b = cos(x)
ta += a
tb += b
end
ta, tb
end
function bar(X)
ta = 0.0
tb = 0.0
for x in X
a, b = sincos(x)
ta += a
tb += b
end
ta, tb
end
N = 1_000_000
X = rand(N)
@time foo(X)
@time bar(X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment