TIMING.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. #include "timing.h"
  10. #ifdef TIMING
  11. #ifndef __alpha
  12. static struct {
  13. unsigned int st_time[2];
  14. unsigned int cycles;
  15. unsigned int calls;
  16. } timingInfo[64];
  17. static int timingEnters;
  18. static void rdtsc(unsigned int t[2])
  19. {
  20. __asm
  21. {
  22. mov esi, t
  23. _emit 0xf
  24. _emit 0x31
  25. mov [esi], eax
  26. mov [esi+4], edx
  27. }
  28. }
  29. void _timingInit()
  30. {
  31. memset(timingInfo,0,sizeof(timingInfo));
  32. }
  33. void _timingEnter(int which)
  34. {
  35. // if (!timingEnters++) __asm cli
  36. rdtsc(timingInfo[which].st_time);
  37. }
  38. void _timingLeave(int which)
  39. {
  40. unsigned int t[2];
  41. rdtsc(t);
  42. // if (!--timingEnters) __asm sti
  43. if (t[1]==timingInfo[which].st_time[1])
  44. {
  45. timingInfo[which].cycles += t[0]-timingInfo[which].st_time[0];
  46. }
  47. else
  48. {
  49. timingInfo[which].cycles += t[0]+(0xffffffff-timingInfo[which].st_time[0]);
  50. }
  51. timingInfo[which].calls++;
  52. }
  53. void _timingPrint()
  54. {
  55. int x;
  56. FILE *fp = fopen("C:\\timings.txt","a+t");
  57. for (x = 0; x < sizeof(timingInfo)/sizeof(timingInfo[0]); x ++)
  58. {
  59. if (timingInfo[x].calls)
  60. fprintf(fp,"%d: %d calls, %d clocks/call\n",x,timingInfo[x].calls,timingInfo[x].cycles/timingInfo[x].calls);
  61. }
  62. _timingInit();
  63. fclose(fp);
  64. }
  65. #endif
  66. #endif