Skip to content

Commit 09c9686

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 09c9686

File tree

3 files changed

+119
-3
lines changed

3 files changed

+119
-3
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ libtwin.a_files-y += backend/linux_input.c
111111
endif
112112

113113
# Standalone application
114+
ifeq ($(CONFIG_PERFORMANCE_TEST), y)
115+
target-y += demo-$(BACKEND)
116+
demo-$(BACKEND)_depends-y += $(target.a-y)
117+
demo-$(BACKEND)_files-y = apps/perf.c
118+
demo-$(BACKEND)_includes-y := include
119+
demo-$(BACKEND)_ldflags-y := \
120+
$(target.a-y) \
121+
$(TARGET_LIBS)
122+
endif
114123

115124
ifeq ($(CONFIG_DEMO_APPLICATIONS), y)
116125
target-y += demo-$(BACKEND)

apps/perf.c

Lines changed: 103 additions & 0 deletions
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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ config LOADER_GIF
5858

5959
endmenu
6060

61-
menu "Demo Applications"
61+
choice
62+
prompt "Application Selection"
63+
default DEMO_APPLICATIONS
64+
65+
config PERFORMANCE_TEST
66+
bool "Built performance test"
6267

6368
config DEMO_APPLICATIONS
6469
bool "Build demo applications"
65-
default y
6670

6771
config DEMO_MULTI
6872
bool "Build multi demo"
@@ -98,4 +102,4 @@ config DEMO_ANIMATION
98102
bool "Build animation demo"
99103
default y
100104
depends on DEMO_APPLICATIONS
101-
endmenu
105+
endchoice

0 commit comments

Comments
 (0)