1
0

writespeed.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * File : writespeed.c
  3. * This file is part of RT-TestCase in RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-02-10 Bernard first version
  13. */
  14. #include <rtthread.h>
  15. #include <dfs_posix.h>
  16. void writespeed(const char* filename, int total_length, int block_size)
  17. {
  18. int fd;
  19. char *buff_ptr;
  20. rt_tick_t tick;
  21. fd = open(filename, 0, O_WRONLY);
  22. if (fd < 0)
  23. {
  24. rt_kprintf("open file:%s failed\n", filename);
  25. return;
  26. }
  27. buff_ptr = rt_malloc(block_size);
  28. if (buff_ptr == RT_NULL)
  29. {
  30. rt_kprintf("no memory\n");
  31. close(fd);
  32. return;
  33. }
  34. /* prepare write data */
  35. tick = rt_tick_get();
  36. tick = rt_tick_get() - tick;
  37. /* close file and release memory */
  38. close(fd);
  39. rt_free(buff_ptr);
  40. /* calculate write speed */
  41. rt_kprintf("File write speed: %d byte/s\n", total_length/ (tick/RT_TICK_PER_SECOND));
  42. }
  43. #ifdef RT_USING_FINSH
  44. #include <finsh.h>
  45. FINSH_FUNCTION_EXPORT(writespeed, perform file write test);
  46. #endif