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

Last change on this file since 3582 was 3582, checked in by Sam Hocevar, 10 years ago

Coding style: remove tabs and trailing spaces.

  • Property svn:eol-style set to native
File size: 1.8 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(void)
51{
52    caca_canvas_t *cv;
53    int i;
54    cv = caca_create_canvas(40, 40);
55    for (i = 0; i < PUTCHAR_LOOPS; i++)
56    {
57        caca_put_char(cv, 1, 1, 'x');
58        caca_put_char(cv, 1, 1, 'o');
59    }
60    caca_free_canvas(cv);
61}
62
63int main(int argc, char *argv[])
64{
65    TIME("blit no mask, no clear", blit(0, 0));
66    TIME("blit no mask, clear", blit(0, 1));
67    TIME("blit mask, no clear", blit(1, 0));
68    TIME("blit mask, clear", blit(1, 1));
69    TIME("putchars", putchars());
70    return 0;
71}
72
Note: See TracBrowser for help on using the repository browser.