aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2009-12-20 09:18:48 -0800
committerJohn Hawthorn <john.hawthorn@gmail.com>2009-12-20 09:18:48 -0800
commitc97d443e62bd27755fa62e3f5dc8836c80ae5fc7 (patch)
tree3a1a95b127c1b2e4773a8d2c08f6a60e833a630c /test
parent2803eebe996da45dc13a593a49a2330c829829c1 (diff)
downloadmirror-meh-c97d443e62bd27755fa62e3f5dc8836c80ae5fc7.tar.gz
mirror-meh-c97d443e62bd27755fa62e3f5dc8836c80ae5fc7.tar.bz2
mirror-meh-c97d443e62bd27755fa62e3f5dc8836c80ae5fc7.zip
add performance tests for scaling.
Diffstat (limited to 'test')
-rw-r--r--test/test.c62
-rw-r--r--test/test.h6
2 files changed, 68 insertions, 0 deletions
diff --git a/test/test.c b/test/test.c
new file mode 100644
index 0000000..926d5c2
--- /dev/null
+++ b/test/test.c
@@ -0,0 +1,62 @@
+#include "stdio.h"
+#include "stdlib.h"
+#include "sys/time.h"
+
+#include "../src/meh.h"
+
+#define TESTRUNS 20
+#define STARTTEST(name) int test_##name(){ testname = #name; testsrun++; do
+#define ENDTEST while(0); testspassed++; return 0;}
+#define STARTTIME struct timeval tvs[2];int _i, _j; for(_i = 0; _i < 2; gettimeofday(&tvs[_i], NULL), _i++){for(_j = 0; _j < (_i ? TESTRUNS : 3); _j++)
+#define ENDTIME }long int mselapsed = (tvs[1].tv_sec - tvs[0].tv_sec) * 1000000L + (tvs[1].tv_usec - tvs[0].tv_usec); printf("%s: average time: %li.%.3li ms\n", testname, mselapsed/1000/TESTRUNS, (mselapsed/TESTRUNS)%1000);
+#define assert(x) if(!(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", testname, #x, __FILE__ ,__LINE__);return -1;}
+
+char *testname = NULL;
+int testsrun = 0, testspassed = 0;
+
+typedef int (*test_t)();
+
+STARTTEST(scale){
+ struct image img;
+ img.bufwidth = 1280*2;
+ img.bufheight = 1024*2;
+ img.buf = malloc(img.bufwidth*img.bufheight*4);
+ char *to = malloc(1280*1024*4);
+ STARTTIME{
+ scale(&img, 1280, 1024, 1280, to);
+ }ENDTIME
+ free(to);
+ free(img.buf);
+}ENDTEST
+
+STARTTEST(nearestscale){
+ struct image img;
+ img.bufwidth = 1280*2;
+ img.bufheight = 1024*2;
+ img.buf = malloc(img.bufwidth*img.bufheight*4);
+ char *to = malloc(1280*1024*4);
+ STARTTIME{
+ nearestscale(&img, 1280, 1024, 1280, to);
+ }ENDTIME
+ free(to);
+ free(img.buf);
+}ENDTEST
+
+test_t tests[] = {
+ test_scale,
+ test_nearestscale,
+ NULL
+};
+
+void summary(){
+ printf("%i tests run: %i passed %i failed\n", testsrun, testspassed, testsrun - testspassed);
+}
+
+int main(){
+ test_t *test = tests;
+ for(; *test; test++)
+ (*test)();
+ summary();
+ return 0;
+}
+
diff --git a/test/test.h b/test/test.h
new file mode 100644
index 0000000..1f2e7a0
--- /dev/null
+++ b/test/test.h
@@ -0,0 +1,6 @@
+
+#define STARTTIME
+#define ENDTIME
+
+#define
+