Last active
December 16, 2015 12:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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