25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bench.c 2.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * libcaca benchmark program
  3. * Copyright (c) 2009 Pascal Terjan <pterjan@linuxfr.org>
  4. * 2009 Sam Hocevar <sam@hocevar.net>
  5. *
  6. * This library is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What the Fuck You Want
  9. * to Public License, Version 2, as published by Sam Hocevar. See
  10. * http://www.wtfpl.net/ for more details.
  11. */
  12. #include "config.h"
  13. #include <stdio.h>
  14. #include "caca.h"
  15. #define BLIT_LOOPS 1000000
  16. #define PUTCHAR_LOOPS 50000000
  17. #define TIME(desc, code) \
  18. { \
  19. caca_display_t *dummy = caca_create_display_with_driver(NULL, "null"); \
  20. printf("%-25s: ", desc);\
  21. caca_refresh_display(dummy); \
  22. code; \
  23. caca_refresh_display(dummy); \
  24. printf("%5dms\n", caca_get_display_time(dummy) / 1000); \
  25. caca_free_display(dummy); \
  26. }
  27. static void blit(int mask, int clear)
  28. {
  29. caca_canvas_t *cv, *cv2;
  30. int i;
  31. cv = caca_create_canvas(40, 40);
  32. cv2 = caca_create_canvas(16, 16);
  33. caca_fill_box(cv2, 0, 0, 16, 16, 'x');
  34. for (i = 0; i < BLIT_LOOPS; i++)
  35. {
  36. if(clear)
  37. caca_clear_canvas(cv);
  38. caca_blit(cv, 1, 1, cv2, mask ? cv2 : NULL);
  39. }
  40. caca_free_canvas(cv);
  41. caca_free_canvas(cv2);
  42. }
  43. static void putchars(int optim)
  44. {
  45. caca_canvas_t *cv;
  46. int i;
  47. cv = caca_create_canvas(40, 40);
  48. if(optim)
  49. caca_disable_dirty_rect(cv);
  50. for (i = 0; i < PUTCHAR_LOOPS; i++)
  51. {
  52. caca_put_char(cv, 1, 1, 'x');
  53. caca_put_char(cv, 1, 1, 'o');
  54. }
  55. if(optim)
  56. {
  57. caca_enable_dirty_rect(cv);
  58. caca_add_dirty_rect(cv, 1, 1, 1, 1);
  59. }
  60. caca_free_canvas(cv);
  61. }
  62. int main(int argc, char *argv[])
  63. {
  64. TIME("blit no mask, no clear", blit(0, 0));
  65. TIME("blit no mask, clear", blit(0, 1));
  66. TIME("blit mask, no clear", blit(1, 0));
  67. TIME("blit mask, clear", blit(1, 1));
  68. TIME("putchars, no optim", putchars(0));
  69. TIME("putchars, optim", putchars(1));
  70. return 0;
  71. }