rtimer.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /****************************************************************************
  2. *
  3. * MODULE: iostream
  4. *
  5. * COPYRIGHT (C) 2007 Laura Toma
  6. *
  7. *
  8. * Iostream is a library that implements streams, external memory
  9. * sorting on streams, and an external memory priority queue on
  10. * streams. These are the fundamental components used in external
  11. * memory algorithms.
  12. * Credits: The library was developed by Laura Toma. The kernel of
  13. * class STREAM is based on the similar class existent in the GPL TPIE
  14. * project developed at Duke University. The sorting and priority
  15. * queue have been developed by Laura Toma based on communications
  16. * with Rajiv Wickremesinghe. The library was developed as part of
  17. * porting Terraflow to GRASS in 2001. PEARL upgrades in 2003 by
  18. * Rajiv Wickremesinghe as part of the Terracost project.
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  28. * General Public License for more details. *
  29. * **************************************************************************/
  30. #include <sys/time.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <strings.h>
  34. //#include <rtimer.h>
  35. #include <grass/iostream/rtimer.h>
  36. char *
  37. rt_sprint_safe(char *buf, Rtimer rt) {
  38. if(rt_w_useconds(rt) == 0) {
  39. sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
  40. 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  41. } else {
  42. sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
  43. rt_u_useconds(rt)/1000000,
  44. 100.0*rt_u_useconds(rt)/rt_w_useconds(rt),
  45. rt_s_useconds(rt)/1000000,
  46. 100.0*rt_s_useconds(rt)/rt_w_useconds(rt),
  47. rt_w_useconds(rt)/1000000,
  48. 100.0*(rt_u_useconds(rt)+rt_s_useconds(rt)) / rt_w_useconds(rt));
  49. }
  50. return buf;
  51. }