source: libcaca/trunk/test/bench.c @ 4303

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

Allow to temporarily disable dirty rectangle handling. This allows for huge
speedups when the calling application knows the dirty rectangle covered by
a complex operation.

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
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://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#include "config.h"
14
15#include <stdio.h>
16
17#include "caca.h"
18
19#define BLIT_LOOPS 1000000
20#define PUTCHAR_LOOPS 50000000
21
22#define TIME(desc, code) \
23{ \
24    caca_display_t *dummy = caca_create_display_with_driver(NULL, "null"); \
25    printf("%-25s: ", desc);\
26    caca_refresh_display(dummy); \
27    code; \
28    caca_refresh_display(dummy); \
29    printf("%5dms\n", caca_get_display_time(dummy) / 1000); \
30    caca_free_display(dummy); \
31}
32
33static void blit(int mask, int clear)
34{
35    caca_canvas_t *cv, *cv2;
36    int i;
37    cv = caca_create_canvas(40, 40);
38    cv2 = caca_create_canvas(16, 16);
39    caca_fill_box(cv2, 0, 0, 16, 16, 'x');
40    for (i = 0; i < BLIT_LOOPS; i++)
41    {
42        if(clear)
43            caca_clear_canvas(cv);
44        caca_blit(cv, 1, 1, cv2, mask ? cv2 : NULL);
45    }
46    caca_free_canvas(cv);
47    caca_free_canvas(cv2);
48}
49
50static void putchars(int optim)
51{
52    caca_canvas_t *cv;
53    int i;
54    cv = caca_create_canvas(40, 40);
55    if(optim)
56        caca_disable_dirty_rect(cv);
57    for (i = 0; i < PUTCHAR_LOOPS; i++)
58    {
59        caca_put_char(cv, 1, 1, 'x');
60        caca_put_char(cv, 1, 1, 'o');
61    }
62    if(optim)
63    {
64        caca_enable_dirty_rect(cv);
65        caca_add_dirty_rect(cv, 1, 1, 1, 1);
66    }
67    caca_free_canvas(cv);
68}
69
70int main(int argc, char *argv[])
71{
72    TIME("blit no mask, no clear", blit(0, 0));
73    TIME("blit no mask, clear", blit(0, 1));
74    TIME("blit mask, no clear", blit(1, 0));
75    TIME("blit mask, clear", blit(1, 1));
76    TIME("putchars, no optim", putchars(0));
77    TIME("putchars, optim", putchars(1));
78    return 0;
79}
80
Note: See TracBrowser for help on using the repository browser.