Skip to content

Instantly share code, notes, and snippets.

@simonbyrne
Created Jul 28, 2014
Embed
What would you like to do?
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