[非淼]关于转换时间
  • 板块学术版
  • 楼主XYY1411
  • 当前回复14
  • 已保存回复14
  • 发布时间2021/5/16 15:15
  • 上次更新2023/11/4 23:11:03
查看原帖
[非淼]关于转换时间
129562
XYY1411楼主2021/5/16 15:15

两种到 long long 的转换:

  1. (ll)a

  2. 1LL*a

那个快?

我试图自测,使用以下代码:

code1\rm 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\rm 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;
}

发现,哪个在上面哪个慢。

所以到底哪个快哪个慢?

2021/5/16 15:15
加载中...