source: libcaca/trunk/tests/bench.c @ 3572

Last change on this file since 3572 was 3572, checked in by Sam Hocevar, 11 years ago

Use a dummy display to compute benchmark time to avoid relying on <time.h>.

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1#include "config.h"
2
3#include <stdio.h>
4
5#include "caca.h"
6
7#define TIME(desc, code) \
8{ \
9    caca_display_t *dummy = caca_create_display_with_driver(NULL, "null"); \
10    printf("%-25s: ", desc);\
11    caca_refresh_display(dummy); \
12    code; \
13    caca_refresh_display(dummy); \
14    printf("%dms\n", caca_get_display_time(dummy) / 1000); \
15    caca_free_display(dummy); \
16}
17
18static void blit(int mask, int clear)
19{
20    caca_canvas_t *cv, *cv2;
21    int i;
22    cv = caca_create_canvas(40, 40);
23    cv2 = caca_create_canvas(16, 16);
24    caca_fill_box(cv2, 0, 0, 16, 16, 'x');
25    for (i=0; i<1000000; i++) {
26      if(clear)
27              caca_clear_canvas(cv);
28      caca_blit(cv, 1, 1, cv2, mask?cv2:NULL);
29    }
30    caca_free_canvas(cv);
31    caca_free_canvas(cv2);
32}
33
34static void putchars(void)
35{
36    caca_canvas_t *cv;
37    int i;
38    cv = caca_create_canvas(40, 40);
39    for (i=0; i<50000000; i++) {
40      caca_put_char(cv, 1, 1, 'x');
41      caca_put_char(cv, 1, 1, 'o');
42    }
43    caca_free_canvas(cv);
44}
45
46int main(int argc, char *argv[])
47{
48    TIME("blit no mask, no clear",blit(0, 0));
49    TIME("blit no mask, clear",blit(0, 1));
50    TIME("blit mask, no clear",blit(1, 0));
51    TIME("blit mask, clear",blit(1, 1));
52    TIME("putchars",putchars());
53    return 0;
54}
55
Note: See TracBrowser for help on using the repository browser.