constexpr and performance result
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 { Thank You for answer. |
would be nice to demonstrate it somehow. Or at least explain how did you measure it?
|
Quote:
Code:
#include <iostream> Code:
g++ -std=c++11 -O2 test.cpp then in terminal i have result: Code:
CONSTEXPR FIB BENCHMARK |
That could have been entirely optimized away. The standard benchark method is calculating fib(largeint) modulo 1000000009
|
yes, n=20 is not really useful, try other numbers too (like 1234567890).
|
Since you defined it as a "constant expression," the compiler doesn't have to generate a function at all.
|
Quote:
Would be nice to see the object code to check it. |
All times are GMT -5. The time now is 05:05 AM. |