(C++)合并排序执行时间



我在网上找到了一个关于测量合并排序执行时间的代码。我无法理解将值放入数组中的部分。在该行中:b[i] = i + 352;值 352 有什么用?如果我想要 2000、3000、4000 等的数组大小,下一个值是什么。

        int b[1000];
        int i;
            for (i = 0; i < 1001; i++) {
            b[i] = i + 352 ;
            } //put values into array
        int n = sizeof b / sizeof b[0];
        clock_t start = clock();
        merge_sort(b, n);
        clock_t end = clock();
        double elapsed1 = ((end - start) / CLOCKS_PER_SEC);// seconds elapse
        printf("Time elapsed for merge 1000: %fn", elapsed1);

352 只是一个整数文字。它只是将值 i+352 存储在 b[i],因此 b[0] 将具有值 352,b[1] 将具有值 353,依此类推。此外,如果进一步将数组大小增加到 2000,则 arr[1999] 将包含 1999+352。

计算任何程序运行时间的一种更好方法可能是这个。
cmd/v:on/c "echo !时间!&youprogram.exe & echo !时间!

最新更新