From bbd9f470f04dfd8d7b2afe80ae4a2eef7b841467 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Tue, 19 Jan 2010 23:30:28 +0000 Subject: [PATCH] add file read speed test. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@321 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- examples/file/readspeed.c | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/file/readspeed.c diff --git a/examples/file/readspeed.c b/examples/file/readspeed.c new file mode 100644 index 000000000..e76471fb4 --- /dev/null +++ b/examples/file/readspeed.c @@ -0,0 +1,50 @@ +#include +#include + +void readspeed(const char* filename, int block_size) +{ + int fd; + char *buff_ptr; + rt_size_t total_length; + rt_tick_t tick; + + fd = open(filename, 0, DFS_O_RDONLY); + if (fd < 0) + { + rt_kprintf("open file:%s failed\n", filename); + return; + } + + buff_ptr = rt_malloc(block_size); + if (buff_ptr == RT_NULL) + { + rt_kprintf("no memory\n"); + close(fd); + + return; + } + + tick = rt_tick_get(); + total_length = 0; + while (1) + { + int length; + length = read(fd, buff_ptr, block_size); + + if (length == 0) break; + total_length += length; + } + tick = rt_tick_get() - tick; + + /* close file and release memory */ + close(fd); + rt_free(buff_ptr); + + /* calculate read speed */ + rt_kprintf("File read speed: %d byte/s\n", total_length/ (tick/RT_TICK_PER_SECOND)); +} + +#ifdef RT_USING_FINSH +#include +FINSH_FUNCTION_EXPORT(readspeed, perform file read test); +#endif