/*********************************************************************************
|
* Copyright: (C) 2025 LingYun IoT System Studio
|
* All rights reserved.
|
*
|
* Filename: eclipse.c
|
* Description: This file is a time eclipse example
|
*
|
* Version: 1.0.0(10/15/2025)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "10/15/2025 05:19:22 PM"
|
*
|
********************************************************************************/
|
|
#include <stdio.h>
|
#include <time.h>
|
#include <unistd.h>
|
|
int main()
|
{
|
struct timespec start, end;
|
long eclipse;
|
|
// 获取开始时间(高精度)
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
|
// 模拟耗时操作
|
sleep(1);
|
|
// 获取结束时间
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
|
// 计算耗时(纳秒)
|
eclipse = (end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec);
|
printf("耗时: %.3f 毫秒\n", eclipse / 1e6);
|
|
return 0;
|
}
|