c/c++ tricks

auto __start = std::chrono::high_resolution_clock::now();

std::cout << __LINE__ << "L\telapsed=" << std::chrono::duration_cast<std::chrono::nanoseconds>((std::chrono::high_resolution_clock::now() - __start)).count() << "ns" << std::endl;
// printf("%uL\telapsed=%lldns\n", __LINE__, std::chrono::duration_cast<std::chrono::nanoseconds>((std::chrono::high_resolution_clock::now() - __start)).count());
struct timeval __start, __end;gettimeofday(&__start, NULL);

gettimeofday(&__end, NULL), printf("%uL\telapsed=%ldus\n", __LINE__, 1000000 * (__end.tv_sec - __start.tv_sec) + __end.tv_usec - __start.tv_usec);
struct timespec __start, __end; clock_gettime(CLOCK_MONOTONIC, &__start);

clock_gettime(CLOCK_MONOTONIC, &__end), printf("%uL\telapsed=%ldns\n", __LINE__, (__end.tv_sec - __start.tv_sec) * (1000l * 1000 * 1000) + __end.tv_nsec - __start.tv_nsec);
posted @ 2021-11-03 16:39  Tifa_Best  阅读(45)  评论(0编辑  收藏  举报