doc: Add screenshot to spiv page.
[gfxprim/pasky.git] / tests / gfx / gfx_benchmark.c
blob4d5674ce8b9c520e04e45d5792a0c9e8ba003b81
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <core/GP_Context.h>
24 #include <gfx/GP_Gfx.h>
26 #include "tst_test.h"
28 static int bench_line(GP_PixelType type)
30 GP_Context *img = GP_ContextAlloc(800, 600, type);
32 if (img == NULL) {
33 tst_err("Malloc failed");
34 return TST_UNTESTED;
37 unsigned int i;
39 for (i = 0; i < 100000; i++) {
40 GP_Line(img, 0 + i % 100, 0 - i % 100,
41 800 - i%200, 600 + i%200, i % 0xff);
44 return TST_SUCCESS;
47 static int bench_line_1bpp(void)
49 return bench_line(GP_PIXEL_G1);
52 static int bench_line_2bpp(void)
54 return bench_line(GP_PIXEL_G2);
57 static int bench_line_4bpp(void)
59 return bench_line(GP_PIXEL_G4);
62 static int bench_line_8bpp(void)
64 return bench_line(GP_PIXEL_G8);
67 static int bench_line_32bpp(void)
69 return bench_line(GP_PIXEL_RGB888);
72 static int bench_circle(GP_PixelType type)
74 GP_Context *img = GP_ContextAlloc(800, 600, type);
76 if (img == NULL) {
77 tst_err("Malloc failed");
78 return TST_UNTESTED;
81 unsigned int i;
83 for (i = 0; i < 100000; i++) {
84 GP_Circle(img, img->w/2, img->h/2, i % 1000, i%0xff);
87 return TST_SUCCESS;
90 static int bench_circle_1bpp(void)
92 return bench_circle(GP_PIXEL_G1);
95 static int bench_circle_2bpp(void)
97 return bench_circle(GP_PIXEL_G2);
100 static int bench_circle_4bpp(void)
102 return bench_circle(GP_PIXEL_G4);
105 static int bench_circle_8bpp(void)
107 return bench_circle(GP_PIXEL_G8);
110 static int bench_circle_32bpp(void)
112 return bench_circle(GP_PIXEL_RGB888);
115 const struct tst_suite tst_suite = {
116 .suite_name = "GFX Benchmark",
117 .tests = {
118 {.name = "Line 1BPP", .tst_fn = bench_line_1bpp,
119 .bench_iter = 10},
120 {.name = "Line 2BPP", .tst_fn = bench_line_2bpp,
121 .bench_iter = 10},
122 {.name = "Line 4BPP", .tst_fn = bench_line_4bpp,
123 .bench_iter = 10},
124 {.name = "Line 8BPP", .tst_fn = bench_line_8bpp,
125 .bench_iter = 10},
126 {.name = "Line 32BPP", .tst_fn = bench_line_32bpp,
127 .bench_iter = 10},
129 {.name = "Circle 1BPP", .tst_fn = bench_circle_1bpp,
130 .bench_iter = 10},
131 {.name = "Circle 2BPP", .tst_fn = bench_circle_2bpp,
132 .bench_iter = 10},
133 {.name = "Circle 4BPP", .tst_fn = bench_circle_4bpp,
134 .bench_iter = 10},
135 {.name = "Circle 8BPP", .tst_fn = bench_circle_8bpp,
136 .bench_iter = 10},
137 {.name = "Circle 32BPP", .tst_fn = bench_circle_32bpp,
138 .bench_iter = 10},
140 {.name = NULL},