学习笔记8+代码

一、苏格拉底挑战







二、遇见的问题



三、实践+代码


gettimeofday:

#include <stdio.h>
#include <sys/time.h>

int main() {
    struct timeval current_time;
    if (gettimeofday(&current_time, NULL) == 0) {
        printf("Seconds: %ld\n", current_time.tv_sec);
        printf("Microseconds: %ld\n", current_time.tv_usec);
    } else {
        perror("gettimeofday");
    }
    return 0;
}

settimeofday:

#include <stdio.h>
#include <time.h>

int main() {
    time_t current_time;
    current_time = time(NULL);
    printf("Seconds since 1970-01-01 00:00:00 UTC: %ld\n", current_time);
    return 0;
}

time:

#include <stdio.h>
#include <sys/times.h>

int main() {
    struct tms process_times;
    clock_t start, end;

    start = times(&process_times);

    // 在这里执行一些计算密集型任务

    end = times(&process_times);

    printf("User time: %ld\n", process_times.tms_utime);
    printf("System time: %ld\n", process_times.tms_stime);

    return 0;
}
posted @ 2023-11-02 15:07  20211423袁艺  阅读(3)  评论(0编辑  收藏  举报