首页 > 解决方案 > VSCode Code Runner 比直接在我的 Linux 终端上运行代码要快

问题描述

我有这个我正在研究的基本 CSV 搜索子字符串算法,我正在测量在我的树莓派 4 终端上运行它与在 CodeRunner 上运行它之间的性能。我的 CodeRunner 运行速度比在终端中执行此操作要快得多./performanceTest我想知道 CodeRunner 是否甚至没有在我的 Pi 上运行,因为我正在进入它?这是我写的代码:

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

void TP_4091() {
    FILE* stream = fopen("test.csv", "r");
    if (!stream) {
        printf("Error occured");
    }
    struct timespec tstart = {0, 0}, tend = {0, 0};
    clock_gettime(CLOCK_MONOTONIC, &tstart);
    char searchCharacter[] = "New York";
    char buf[1024]; // storing the first 1024 lines into a buffer
    while (fgets(buf, sizeof(buf), stream)) {
        char *token;

        token = strtok(buf, ",");

        while(token != NULL) {
            if (strstr(token, "New York") != NULL) {
                printf("%s ", buf);
            }
            token = strtok(NULL, ",");
        }
        printf("\n");
    }
    clock_gettime(CLOCK_MONOTONIC, &tend);
    long ttotal = tend.tv_nsec - tstart.tv_nsec;
    printf("Time taken to run the function in normal C: %lu\n", ttotal);
    fclose(stream);
}

int main(void *ctx)
{
    TP_4091();
}

这是我在 CodeRunner 上运行它时收到的时间,68018,这是我从 252627 得到的时间./performanceTest。我使用 clock_gettime 的原因是有一个 BPF 等效项可以让我比较 BPF 性能,不其他原因。

标签: cvisual-studio-codetime.hvscode-code-runner

解决方案


推荐阅读