c - 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 性能,不其他原因。
解决方案
推荐阅读
- ruby-on-rails - 语法错误,意外的输入结束,期待关键字结束。运行功能文件的 rspec 时
- node.js - 来自docker内部反应的代理wordpress
- html - 如果我悬停父级,如何触发子级?
- python - 如何在使用 get_duplicates() 时从废弃的代码中切换
- android - 如何在 Android 6.0 中正确请求位置权限?
- c# - GridView - 打开带有 ID 的新选项卡自定义按钮
- ios - 使用更新查询更新 sqlite 表中的值时出现问题
- xml - 如何在 MarkLogic 中包含子元素作为单词查询的一部分
- windows - “windbg”以系统帐户运行时无法加载符号
- sql-server - 什么图像用于通过 bitbucket 云自动将 SSIS 包部署到 SQL Server?