gpt4 book ai didi

c - 某些对 "calloc"的调用速度快得令人怀疑

转载 作者:可可西里 更新时间:2023-11-01 11:49:03 25 4
gpt4 key购买 nike

<分区>

我正在使用“Perf”(Linux、gcc)进行基准测试。

分配内存时:

point_1 = calloc (100000000, 16);  //this takes nearly 1 second and perf find 27M transfers from RAM->CACHE and 1M from CACHE->RAM 

没关系。

但是当尝试分配两个数组时:

point_1 = calloc (100000000, 16); 
point_2 = calloc (100000000, 16);
//again, program takes nearly 1 second, 27M transfers RAM-CACAHE, 1M CACHE->RAM

看起来,第二个“calloc”(以及所有后续)的行为类似于“malloc”。我正在使用“gcc 版本 4.9.2 (Ubuntu 4.9.2-0ubuntu1~12.04)”。否则程序工作正常。

这样可以吗?

这里有更多的测试和结果:

Time for allocating of data structure 1: 0.976468 
Perf: R:27M, W:1M

Time for allocating of data structure 1: 0.975402
Time for initialization of data structure 1 to value of 7: 0.296787
Perf: R: 52M, W: 26M

Time for allocating of data structure 1: 0.976034
Time for initialization of data structure 1 to value of 7: 0.313554
Time for allocating of data structure 2: 0.000031 <-- misbehaving
Perf: R: 52M, W:26M

Time for allocating of data structure 1: 0.975403
Time for initialization of data structure 1 to value of 7: 0.313710
Time for allocating of data structure 2: 0.000031 <-- misbehaving
Time for initialization of data structure 2 to value of 7: 0.809855
Perf: R:79M, W: 53M

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com