Skip to content

Commit d70df26

Browse files
committed
Add the performance test program
This program measures the runtime for the compositing functions. We can observe the runtime change with the compositing size.
1 parent 980bd4c commit d70df26

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*.a
55
demo-*
66
.demo-*
7+
mado-perf
8+
.mado-perf
79

810
# Swap
911
[._]*.s[a-v][a-z]

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ libtwin.a_files-y += backend/fbdev.c
110110
libtwin.a_files-y += backend/linux_input.c
111111
endif
112112

113+
# Performance tester
114+
115+
ifeq ($(CONFIG_PERFORMANCE_TEST), y)
116+
target-$(CONFIG_PERFORMANCE_TEST) += apps/mado-perf
117+
apps/mado-perf_depends-y += $(target.a-y)
118+
apps/mado-perf_files-y += apps/perf.c
119+
apps/mado-perf_includes-y := include
120+
apps/mado-perf_ldflags-y := \
121+
$(target.a-y) \
122+
$(TARGET_LIBS)
123+
endif
124+
113125
# Standalone application
114126

115127
ifeq ($(CONFIG_DEMO_APPLICATIONS), y)

apps/perf.c

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Twin - A Tiny Window System
3+
* Copyright (c) 2024 National Cheng Kung University, Taiwan
4+
* All rights reserved.
5+
*/
6+
7+
#include <assert.h>
8+
#include <stdio.h>
9+
#include <string.h>
10+
#include <sys/time.h>
11+
#include <time.h>
12+
13+
#include "twin.h"
14+
15+
#define TEST_PIX_WIDTH 1200
16+
#define TEST_PIX_HEIGHT 800
17+
18+
static twin_pixmap_t *src32, *dst32;
19+
static int twidth, theight, titers;
20+
21+
static void test_argb32_source_argb32(void)
22+
{
23+
twin_operand_t srco = {.source_kind = TWIN_PIXMAP, .u.pixmap = src32};
24+
twin_composite(dst32, 0, 0, &srco, 0, 0, NULL, 0, 0, TWIN_SOURCE, twidth,
25+
theight);
26+
}
27+
28+
static void test_argb32_over_argb32(void)
29+
{
30+
twin_operand_t srco = {.source_kind = TWIN_PIXMAP, .u.pixmap = src32};
31+
twin_composite(dst32, 0, 0, &srco, 0, 0, NULL, 0, 0, TWIN_OVER, twidth,
32+
theight);
33+
}
34+
35+
static void do_test(const char *name, void (*test)(void))
36+
{
37+
struct timeval start, end;
38+
unsigned long long sus, eus;
39+
char spc[128];
40+
char *s;
41+
int i;
42+
43+
printf("%s", name);
44+
45+
gettimeofday(&start, NULL);
46+
for (i = 0; i < titers; i++)
47+
test();
48+
gettimeofday(&end, NULL);
49+
sus = (unsigned long long) start.tv_sec * 1000000ull + start.tv_usec;
50+
eus = (unsigned long long) end.tv_sec * 1000000ull + end.tv_usec;
51+
52+
s = spc;
53+
for (i = strlen(name); i < 40; i++)
54+
*(s++) = ' ';
55+
*s = 0;
56+
printf("%s %f sec\n", spc, ((float) (eus - sus)) / 1000000.0);
57+
}
58+
59+
#define DO_TEST(name) do_test(#name, test_##name)
60+
61+
static void do_tests(int width, int height, int iters)
62+
{
63+
twidth = width;
64+
theight = height;
65+
titers = iters;
66+
67+
DO_TEST(argb32_source_argb32);
68+
DO_TEST(argb32_over_argb32);
69+
}
70+
71+
static void do_all_tests(const char *title,
72+
int len_init,
73+
int len_max,
74+
int len_incre,
75+
int iters)
76+
{
77+
for (int len = len_init; len < len_max; len += len_incre) {
78+
printf("[ %s: %dx%dx%d ]\n", title, len, len, iters);
79+
do_tests(len, len, iters);
80+
}
81+
82+
printf("\n");
83+
}
84+
85+
int main(void)
86+
{
87+
/* Create some test pixmaps */
88+
src32 = twin_pixmap_from_file("assets/tux.png", TWIN_ARGB32);
89+
assert(src32);
90+
dst32 = twin_pixmap_create(TWIN_ARGB32, TEST_PIX_WIDTH, TEST_PIX_HEIGHT);
91+
assert(dst32);
92+
93+
/* fill pixmaps */
94+
twin_fill(dst32, 0x80112233, TWIN_SOURCE, 0, 0, TEST_PIX_WIDTH,
95+
TEST_PIX_HEIGHT);
96+
97+
/* pre-touch data */
98+
test_argb32_source_argb32();
99+
100+
do_all_tests("Pixmap", 7, 18, 2, 1000000);
101+
102+
return 0;
103+
}

configs/Kconfig

+9-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ config LOADER_GIF
5858

5959
endmenu
6060

61+
menu "Performance Testers"
62+
63+
config PERFORMANCE_TEST
64+
bool "Build composite tester"
65+
default y
66+
67+
endmenu
68+
6169
menu "Demo Applications"
6270

6371
config DEMO_APPLICATIONS
@@ -98,4 +106,4 @@ config DEMO_ANIMATION
98106
bool "Build animation demo"
99107
default y
100108
depends on DEMO_APPLICATIONS
101-
endmenu
109+
endmenu

0 commit comments

Comments
 (0)