4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-06 21:54:34 +08:00

Merge pull request #3968 from DavidLin1577/patch-8

Update writespeed.c
This commit is contained in:
Bernard Xiong 2020-10-18 13:53:25 +08:00 committed by GitHub
commit 917beb7462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,31 +32,31 @@ void writespeed(const char* filename, int total_length, int block_size)
return; return;
} }
/* prepare write data */ /* prepare write data */
for (index = 0; index < block_size; index++) for (index = 0; index < block_size; index++)
{ {
buff_ptr[index] = index; buff_ptr[index] = index;
} }
index = 0; index = 0;
/* get the beginning tick */ /* get the beginning tick */
tick = rt_tick_get(); tick = rt_tick_get();
while (index < total_length / block_size) while (index < total_length / block_size)
{ {
length = write(fd, buff_ptr, block_size); length = write(fd, buff_ptr, block_size);
if (length != block_size) if (length != block_size)
{ {
rt_kprintf("write failed\n"); rt_kprintf("write failed\n");
break; break;
} }
index ++; index ++;
} }
tick = rt_tick_get() - tick; tick = rt_tick_get() - tick;
/* close file and release memory */ /* close file and release memory */
close(fd); close(fd);
rt_free(buff_ptr); rt_free(buff_ptr);
/* calculate write speed */ /* calculate write speed */
rt_kprintf("File write speed: %d byte/s\n", total_length / tick * RT_TICK_PER_SECOND); rt_kprintf("File write speed: %d byte/s\n", total_length / tick * RT_TICK_PER_SECOND);