Max 与 max
突然发现 , 在\(cpp\)中 , 计算\(10^9\) , 如果用\(std::max\)大概\(1000ms\) , , 内联函数也差不多\(1000ms\) , 而用\(define\)大概不到\(300ms\)
#include<bits/stdc++.h>
using namespace std;
#define Max(a,b) (a)<(b)?(b):(a)
int mx(int a,int b) {
return a<b?b:a;
}
inline int read() {
int res = 0,f= 1;
char ch = getchar();
while (ch >'9' || ch <'0') {
if (ch=='-')
f= -1;
ch = getchar();
}
while (ch >='0' && ch <='9') {
res = res * 10 + ch - '0';
ch = getchar();
}
return res*f;
}
int main() {
auto start = std::chrono::high_resolution_clock::now();
int ans = 1;
for (int i =1;i<=1e9;i++) {
ans= mx(1,2);
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count();
std::cout << "Elapsed time: " << duration << " ms\n";
return 0;
}

浙公网安备 33010602011771号