小编chu*_*9ri的帖子

文件 I/O 性能好得令人难以置信?

我运行了一个简单的文件 I/O 性能测试。我将 1GB 数据写入文件并测量所用时间。结果显示,写入时间仅需约0.45秒,性能超过17Gbps。我知道这是不可能的,但我在我的测试代码中找不到任何问题。以下是我的测试例程。我可以在 d:\a.bin 中看到正确的文件。

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

int main()
{
    char *ioBuf;
    int i, io_buf_size = 1024 * 1024;
    unsigned int io_amt = 0;
    FILE *fp;
    clock_t start, end;
    double elapsed;

    ioBuf = (char *)malloc(1024 * 1024 * sizeof(char));

    for (i = 0; i < io_buf_size; i++) {
        ioBuf[i] = i % 255;
    }

    if ((fp = fopen("d:\\a.bin", "wb")) == NULL) {
        printf("open file fail, err  \n");
        return 1;
    }

    start = clock();
    for …
Run Code Online (Sandbox Code Playgroud)

c io performance file

3
推荐指数
1
解决办法
225
查看次数

标签 统计

c ×1

file ×1

io ×1

performance ×1