aboutsummaryrefslogtreecommitdiffstats
path: root/include/gapk/benchmark.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/gapk/benchmark.h')
-rw-r--r--include/gapk/benchmark.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/include/gapk/benchmark.h b/include/gapk/benchmark.h
new file mode 100644
index 0000000..49c2c36
--- /dev/null
+++ b/include/gapk/benchmark.h
@@ -0,0 +1,60 @@
+#ifndef _BENCHMARK_H
+#define _BENCHMARK_H
+
+/*
+ * This file is part of gapk (GSM Audio Pocket Knife).
+ *
+ * gapk is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gapk is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gapk. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * (C) 2014 Harald Welte <laforge@gnumonks.org>
+ */
+
+#include <gapk/get_cycles.h>
+#include <gapk/codecs.h>
+
+#define NUM_AVG 102400
+
+struct benchmark_cycles {
+ cycles_t enc[NUM_AVG];
+ unsigned int enc_used;
+ cycles_t dec[NUM_AVG];
+ unsigned int dec_used;
+};
+
+extern struct benchmark_cycles codec_cycles[_CODEC_MAX];
+
+static inline void benchmark_stop(enum codec_type codec, int encode, unsigned long cycles)
+{
+ struct benchmark_cycles *bc = &codec_cycles[codec];
+
+ if (encode) {
+ bc->enc_used = (bc->enc_used + 1) % NUM_AVG;
+ bc->enc[bc->enc_used] = cycles;
+ } else {
+ bc->dec_used = (bc->dec_used + 1) % NUM_AVG;
+ bc->dec[bc->dec_used] = cycles;
+ }
+}
+
+#define BENCHMARK_START do { \
+ cycles_t _cycles_start, _cycles_stop; \
+ _cycles_start = get_cycles()
+
+#define BENCHMARK_STOP(x,y) _cycles_stop = get_cycles(); \
+ benchmark_stop(x, y, _cycles_stop - _cycles_start); \
+ } while (0)
+
+void benchmark_dump(void);
+
+#endif