-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixman-cairo.c
75 lines (60 loc) · 2.29 KB
/
pixman-cairo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// gcc pixman-cairo.c -o pixman-cairo -O3 `pkg-config --cflags --libs cairo`
#include <cairo/cairo.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
double get_time_in_seconds() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
void benchmark_pixman_drawing(int width, int height, int iterations) {
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(surface);
double start_time = get_time_in_seconds();
for (int i = 0; i < iterations; i++) {
// Clear surface
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);
// Draw random rectangles
for (int j = 0; j < 100; j++) {
double x = rand() % width;
double y = rand() % height;
double rect_width = rand() % 100;
double rect_height = rand() % 100;
cairo_set_source_rgb(cr, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX);
cairo_rectangle(cr, x, y, rect_width, rect_height);
cairo_fill(cr);
}
// Draw random circles
for (int j = 0; j < 100; j++) {
double x = rand() % width;
double y = rand() % height;
double radius = rand() % 50;
cairo_set_source_rgb(cr, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX);
cairo_arc(cr, x, y, radius, 0, 2 * 3.14159);
cairo_fill(cr);
}
// Flush to ensure rendering happens
cairo_surface_flush(surface);
}
double end_time = get_time_in_seconds();
double elapsed_time = end_time - start_time;
printf("Cairo Benchmark - Width: %d, Height: %d, Iterations: %d\n", width, height, iterations);
printf("Total Time: %.4f seconds\n", elapsed_time);
printf("Average Time per Iteration: %.4f seconds\n", elapsed_time / iterations);
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
int main(int argc, char *argv[]) {
int width = 800;
int height = 600;
int iterations = 1000;
if (argc == 4) {
width = atoi(argv[1]);
height = atoi(argv[2]);
iterations = atoi(argv[3]);
}
benchmark_pixman_drawing(width, height, iterations);
return 0;
}