写内存速度跟块大小(每次写入多少)的关系

#include 
#include 
#include 
#include 
#define TIME_DIFF(ts,te) ((te.tv_sec-ts.tv_sec)+(te.tv_usec-ts.tv_usec)*1.0/1000000)
int main(int argc, char** argv){
	if(argc<2){
		printf("Usage: %s mem_size\n", argv[0]);
		exit(0);
	}
	struct timeval s,e;
	int i;
	char buff[5120000];
	int ranges[] = {1024, 10240, 102400, 1024000, 2048000, 4096000, 5120000};
	int pos = 0;

	int max = 5120000 * 200;

	gettimeofday(&s, NULL);
	for(i=100000;i<99999999;i++){
		pos += sprintf(buff+pos, "%d", i);
		//printf("%d\n", pos);
		pos--;
		if(pos+4>5120000){
			//buff[5120000-1] = 0;
			break;
		}
	}
	gettimeofday(&e, NULL);

	double time_use = TIME_DIFF(s,e);

	int count = sizeof(ranges)/sizeof(int);
	printf("Step count=%d,set up time_use=%10.6f, len=%d, pos=%d\n", count, time_use, strlen(buff), pos);

	char* mem = malloc(max);
	pos = 0;
	for(i=0;iWrite block size=%8d , time_use=%10.6f, copy times=%10d, size=%d, speed %18.6f G/s\n", i, ranges[i], time_use, count2, count1,speed);
	}
	return 0;

}

 

[root@lein lein]# ./tmem 1
Step count=11,set up time_use=  0.186764, len=5119999, pos=5119998
 0>Write block size=    1024 , time_use=  0.065535, copy times=   1000000, size=1024000000, speed          14.552137 G/s
 1>Write block size=   10240 , time_use=  0.060471, copy times=    100000, size=1024000000, speed          15.770771 G/s
 2>Write block size=   12288 , time_use=  0.060541, copy times=     83333, size=1023995904, speed          15.752474 G/s
 3>Write block size=   15360 , time_use=  0.063964, copy times=     66666, size=1023989760, speed          14.909399 G/s
 4>Write block size=   18432 , time_use=  0.124406, copy times=     55555, size=1023989760, speed           7.665746 G/s
 5>Write block size=   20480 , time_use=  0.126707, copy times=     50000, size=1024000000, speed           7.526611 G/s
 6>Write block size=  102400 , time_use=  0.116850, copy times=     10000, size=1024000000, speed           8.161526 G/s
 7>Write block size= 1024000 , time_use=  0.114569, copy times=      1000, size=1024000000, speed           8.324017 G/s
 8>Write block size= 2048000 , time_use=  0.158859, copy times=       500, size=1024000000, speed           6.003275 G/s
 9>Write block size= 4096000 , time_use=  0.251965, copy times=       250, size=1024000000, speed           3.784948 G/s
10>Write block size= 5120000 , time_use=  0.349343, copy times=       200, size=1024000000, speed           2.729908 G/s
[root@lein lein]# ./tmem 1
Step count=11,set up time_use=  0.186145, len=5119999, pos=5119998
 0>Write block size=    1024 , time_use=  0.067273, copy times=   1000000, size=1024000000, speed          14.176182 G/s
 1>Write block size=   10240 , time_use=  0.060461, copy times=    100000, size=1024000000, speed          15.773380 G/s
 2>Write block size=   12288 , time_use=  0.060521, copy times=     83333, size=1023995904, speed          15.757679 G/s
 3>Write block size=   15360 , time_use=  0.062843, copy times=     66666, size=1023989760, speed          15.175354 G/s
 4>Write block size=   18432 , time_use=  0.125159, copy times=     55555, size=1023989760, speed           7.619626 G/s
 5>Write block size=   20480 , time_use=  0.126732, copy times=     50000, size=1024000000, speed           7.525126 G/s
 6>Write block size=  102400 , time_use=  0.115774, copy times=     10000, size=1024000000, speed           8.237379 G/s
 7>Write block size= 1024000 , time_use=  0.115338, copy times=      1000, size=1024000000, speed           8.268518 G/s
 8>Write block size= 2048000 , time_use=  0.162651, copy times=       500, size=1024000000, speed           5.863317 G/s
 9>Write block size= 4096000 , time_use=  0.261244, copy times=       250, size=1024000000, speed           3.650512 G/s
10>Write block size= 5120000 , time_use=  0.344416, copy times=       200, size=1024000000, speed           2.768961 G/s
[root@lein lein]# ./tmem 1
Step count=11,set up time_use=  0.186370, len=5119999, pos=5119998
 0>Write block size=    1024 , time_use=  0.061831, copy times=   1000000, size=1024000000, speed          15.423886 G/s
 1>Write block size=   10240 , time_use=  0.060461, copy times=    100000, size=1024000000, speed          15.773380 G/s
 2>Write block size=   12288 , time_use=  0.060496, copy times=     83333, size=1023995904, speed          15.764191 G/s
 3>Write block size=   15360 , time_use=  0.063776, copy times=     66666, size=1023989760, speed          14.953349 G/s
 4>Write block size=   18432 , time_use=  0.118645, copy times=     55555, size=1023989760, speed           8.037969 G/s
 5>Write block size=   20480 , time_use=  0.126454, copy times=     50000, size=1024000000, speed           7.541670 G/s
 6>Write block size=  102400 , time_use=  0.116525, copy times=     10000, size=1024000000, speed           8.184289 G/s
 7>Write block size= 1024000 , time_use=  0.116533, copy times=      1000, size=1024000000, speed           8.183727 G/s
 8>Write block size= 2048000 , time_use=  0.162223, copy times=       500, size=1024000000, speed           5.878786 G/s
 9>Write block size= 4096000 , time_use=  0.263963, copy times=       250, size=1024000000, speed           3.612909 G/s
10>Write block size= 5120000 , time_use=  0.348008, copy times=       200, size=1024000000, speed           2.740380 G/s
 

你可能感兴趣的:(C,&&,OC,&&,iOS)