From 8ec482dbbf9d8ca6808c55db683f2f5a8623f5f2 Mon Sep 17 00:00:00 2001 From: Eugene Hong Date: Thu, 7 Mar 2024 11:10:18 +0900 Subject: [PATCH] improve optimized version of C++ implementation 1. add constexpr to evaluate the return value at compile time when possible. 2. add inline to set scope of the function to single translation unit, and prevent ODR violation in (little) case of this function used in multiple cpp source file. 3. remove parameter name so that make sure it is not used in function(like the implementation of posfix operators). Result : massive performance improve that made execution time from a couple of nanosecond to 0 nanosecond. see the assembly [here](https://godbolt.org/z/84Tbb7rxx). --- optimized_implementations/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimized_implementations/main.cpp b/optimized_implementations/main.cpp index bc40965..46f617f 100644 --- a/optimized_implementations/main.cpp +++ b/optimized_implementations/main.cpp @@ -1 +1 @@ -bool is_prime(int x){return false;}int main(){return 0;} \ No newline at end of file +constexpr inline bool is_prime(int){return false;}int main(){return 0;} \ No newline at end of file