Complex

Many of cpplex’s operations are many times faster than those in standard C++.

While this is mostly due to standard C++’s NaN checking, it is important to note that for most use cases, NaN checking is unnecessary and causes many functions to be slow.

The following table shows a list of benchmarks comparing operations on cpplex’s cpplex::Complex type and standard C++’s std::complex type. Please note that for operations with multiple definitions, the one with all complex arguments is used for testing.

Each benchmark performs the operation N = 1e+9 times while compound assigning the result to a dummy variable and printing it to ensure volatility. Each benchmark is an average of 3 runs.

Bolded runs indicate non-negligible speed gains by cpplex over standard C++.

Function

cpplex::Complex

std::complex

operator+

0.893s

0.887s

operator-

0.893s

0.894s

operator*

0.894s

1.193s

operator/

0.895s

8.495s

mod / abs

0.910s

0.916s

arg

0.885s

0.891s

conj

0.917s

0.910s

proj

0.916s

0.916s

polar

0.897s

0.904s

exp

0.911s

0.9s

log

0.901s

0.898s

log10

0.901s

0.905s

pow

0.902s

8.649s

sqrt

0.911s

9.134s

sin

0.899s

0.899s

cos

0.893s

0.896s

tan

0.908s

0.906s

asin

0.901s

35.928s

acos

0.906s

42.850s

atan

0.901s

25.061s

sinh

0.901s

0.902s

cosh

0.905s

0.908s

tanh

0.9s

0.9s

asinh

0.911s

35.977s

acosh

0.917s

43.233s

atanh

0.908s

25.853s