两种到 long long
的转换:
(ll)a
1LL*a
那个快?
我试图自测,使用以下代码:
code1
#include <ctime>
#include <cstdio>
using namespace std;
typedef long long ll;
int main() {
int a = 1245465;
clock_t s, t;
s = clock();
for (ll i = 1; i <= 1e9; ++i) (ll)a;
t = clock();
printf("%u\n", t - s);
s = clock();
for (ll i = 1; i <= 1e9; ++i) 1LL*a;
t = clock();
printf("%u\n", t - s);
return 0;
}
code2
#include <ctime>
#include <cstdio>
using namespace std;
typedef long long ll;
int main() {
int a = 1245465;
clock_t s, t;
s = clock();
for (ll i = 1; i <= 1e9; ++i) 1LL*a;
t = clock();
printf("%u\n", t - s);
s = clock();
for (ll i = 1; i <= 1e9; ++i) (ll)a;
t = clock();
printf("%u\n", t - s);
return 0;
}
发现,哪个在上面哪个慢。
所以到底哪个快哪个慢?