constexpr and performance result
by Mac1ek from LinuxQuestions.org on (#6KA9Y)
Hi Why constexpr in function giving extremely high performance when i compare to plain function ?
example:
Code:constexpr auto fib_constexpr(unsigned int n) -> unsigned int {
return (n <= 1) ? n : fib_constexpr(n - 1) + fib_constexpr(n - 2);
}
auto fib_normal(unsigned int n) -> unsigned int {
return (n <= 1) ? n : fib_normal(n - 1) + fib_normal(n - 2);
}this constexpr function giving whole different result in performance
Thank You for answer.
example:
Code:constexpr auto fib_constexpr(unsigned int n) -> unsigned int {
return (n <= 1) ? n : fib_constexpr(n - 1) + fib_constexpr(n - 2);
}
auto fib_normal(unsigned int n) -> unsigned int {
return (n <= 1) ? n : fib_normal(n - 1) + fib_normal(n - 2);
}this constexpr function giving whole different result in performance
Thank You for answer.