Skip to content

Instantly share code, notes, and snippets.

@andrioni
Last active December 16, 2015 12:48
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 andrioni/5436582 to your computer and use it in GitHub Desktop.
Save andrioni/5436582 to your computer and use it in GitHub Desktop.
Small benchmark to compare using MPC and using the julian native complex type with MPFR for the components
function old_complex(n)
a = complex(MPFRFloat(1.1), MPFRFloat(1.1))
sum = complex(MPFRFloat(0))
for i = 1:n
sum += a
end
product = complex(MPFRFloat(1))
for i = 1:n
product *= a
end
return sum, product
end
function mpc_complex(n)
a = MPCComplex(1.1, 1.1)
sum = MPCComplex(0)
for i = 1:n
sum += a
end
product = MPCComplex(1)
for i = 1:n
product *= a
end
return sum, product
end
function benchmark(sz=100000, times=5)
println("MPCComplex")
for i = 1:times
@time mpc_complex(sz)
end
println("Complex{MPFRFloat}")
for i = 1:times
@time old_complex(sz)
end
end
# Just addition
function old_complex_add(n)
a = complex(MPFRFloat(1.1), MPFRFloat(1.1))
sum = complex(MPFRFloat(0))
for i = 1:n
sum += a
end
return sum
end
function mpc_complex_add(n)
a = MPCComplex(1.1, 1.1)
sum = MPCComplex(0)
for i = 1:n
sum += a
end
return sum
end
function benchmark_add(sz=100000, times=5)
println("MPCComplex")
for i = 1:times
@time mpc_complex_add(sz)
end
println("Complex{MPFRFloat}")
for i = 1:times
@time old_complex_add(sz)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment