Home > Back-end > Could you tell me how to do an inline function test program execution time?
Could you tell me how to do an inline function test program execution time?
Time:10-07
Environment: win10 + vs2019
In the Debug mode, the test results as follows: An inline function called running time: 2.766 seconds Call an external function running time: 2.658 seconds Direct running time: 0.232 seconds
In Release mode, the test results as follows: Inline function called running time is: 0 secondsCall external function running time is: 0 secondsDirect running time is: 0 seconds there should be some way to make the inline and running time is almost directly, could you tell me how to write test code or on the compiler choose which options?
The original test code:
# include #include using namespace std; The inline int comp1 (int a, int b) { Return (a & gt; B)? A: b; } Int comp2 (int a, int b) { Return (a & gt; B)? A: b; } Int main () { Double t1, t2; T1=(double) clock (); For (int m=0; M & lt; 10000; M++) For (int n=0; N & lt; 10000; N++) Comp1 (m, n); T2=(double) clock (); Cout & lt; T1=(double) clock (); For (int m=0; M & lt; 10000; M++) For (int n=0; N & lt; 10000; N++) Comp2 (m, n); T2=(double) clock (); Cout & lt; <"Call external function running time is: \ t" & lt; <(t2 - t1)/CLK_TCK & lt; <"Second \ n";
T1=(double) clock (); For (int m=0; M & lt; 10000; M++) For (int n=0; N & lt; 10000; N++) (m & gt; N)? M: n. T2=(double) clock (); Cout & lt; <"Direct running time is: \ t" & lt; <(t2 - t1)/CLK_TCK & lt; <"Second \ n"; return 0; }
CodePudding user response:
The closing of the compiler optimization and dispatch cycle times, project - property - C/C + + - optimization