summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-09-09 21:46:42 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-09-09 21:46:42 +0100
commit483e9d62e4b04f72e541fe562e34c7afb420c93e (patch)
treec6759cd1891e1238b9055e9ed8d42dbe77c68602
parentf690e0d165148d36bd7b5fca2497e81424086787 (diff)
And example benchmarking mode for the tiger
-rw-r--r--demo.c23
-rw-r--r--demo.h1
-rw-r--r--tiger-demo.c17
3 files changed, 38 insertions, 3 deletions
diff --git a/demo.c b/demo.c
index 5f6874d..11b363d 100644
--- a/demo.c
+++ b/demo.c
@@ -16,7 +16,8 @@ int device_get_size(int argc, char **argv, int *width, int *height)
return 1;
}
} else if (strcmp (argv[n], "--size") == 0) {
- if (sscanf (argv[++n], "%dx%d", &w, &h) == 2) {
+ if (n + 1 < argc &&
+ sscanf (argv[++n], "%dx%d", &w, &h) == 2) {
*width = w;
*height = h;
return 1;
@@ -27,6 +28,26 @@ int device_get_size(int argc, char **argv, int *width, int *height)
return 0;
}
+int device_get_benchmark(int argc, char **argv)
+{
+ int n, count;
+
+ count = -1;
+ for (n = 1; n < argc; n++) {
+ if (strncmp (argv[n], "--benchmark=", 12) == 0) {
+ return atoi(argv[n]+12);
+ } else if (strcmp (argv[n], "--benchmark") == 0) {
+ if (n + 1 < argc)
+ return atoi(argv[++n]);
+ else
+ return 0;
+ }
+ }
+
+ return count;
+}
+
+
struct device *device_open(int argc, char **argv)
{
struct device *device = 0;
diff --git a/demo.h b/demo.h
index 02011a3..607a1b5 100644
--- a/demo.h
+++ b/demo.h
@@ -29,6 +29,7 @@ struct slide {
struct device *device_open(int argc, char **argv);
int device_get_size(int argc, char **argv, int *width, int *height);
+int device_get_benchmark(int argc, char **argv);
#if HAVE_GLX
struct device *glx_open (int argc, char **argv);
diff --git a/tiger-demo.c b/tiger-demo.c
index 674ca63..7f4388f 100644
--- a/tiger-demo.c
+++ b/tiger-demo.c
@@ -124,8 +124,12 @@ int main (int argc, char **argv)
double delta;
int frame = 0;
int frames = 0;
+ int benchmark;
device = device_open(argc, argv);
+ benchmark = device_get_benchmark(argc, argv);
+ if (benchmark == 0)
+ benchmark = 20;
gettimeofday(&start, 0); now = last_tty = last_fps = start;
do {
@@ -134,7 +138,7 @@ int main (int argc, char **argv)
tiger (device, fb, scale, rotation);
gettimeofday(&now, NULL);
- if (last_fps.tv_sec)
+ if (benchmark < 0 && last_fps.tv_sec)
fps_draw(fb, device->name, &last_fps, &now);
last_fps = now;
@@ -145,7 +149,7 @@ int main (int argc, char **argv)
if (frame % 256 == 0)
factor = 1./factor;
- {
+ if (benchmark < 0) {
delta = now.tv_sec - last_tty.tv_sec;
delta += (now.tv_usec - last_tty.tv_usec)*1e-6;
frames++;
@@ -156,6 +160,15 @@ int main (int argc, char **argv)
}
}
+ if (benchmark > 0) {
+ delta = now.tv_sec - start.tv_sec;
+ delta += (now.tv_usec - start.tv_usec)*1e-6;
+ if (delta > benchmark) {
+ printf("%.2f fps\n", frame / delta);
+ break;
+ }
+ }
+
scale *= factor;
rotation += 0.1;
} while (1);