From 1f59890cde820629b7ac059672e82e29e7128639 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Sep 2011 12:15:02 +1000 Subject: [PATCH] Tools: added CPUInfo sketch this shows the approximate cost of a wide range of common operations, and the sizes of most data types --- Tools/CPUInfo/CPUInfo.pde | 122 ++++++++++++++++++++++++++++++++++++++ Tools/CPUInfo/Makefile | 4 ++ 2 files changed, 126 insertions(+) create mode 100644 Tools/CPUInfo/CPUInfo.pde create mode 100644 Tools/CPUInfo/Makefile diff --git a/Tools/CPUInfo/CPUInfo.pde b/Tools/CPUInfo/CPUInfo.pde new file mode 100644 index 0000000000..4083ca57e1 --- /dev/null +++ b/Tools/CPUInfo/CPUInfo.pde @@ -0,0 +1,122 @@ +/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*- + +/* + test CPU speed + Andrew Tridgell September 2011 +*/ + +#include +#include + +FastSerialPort0(Serial); + +#define SERIAL0_BAUD 115200 + +void setup() { + Serial.begin(SERIAL0_BAUD, 128, 128); +} + +static void show_sizes(void) +{ + Serial.println("Type sizes:"); + Serial.printf("char : %d\n", sizeof(char)); + Serial.printf("short : %d\n", sizeof(short)); + Serial.printf("int : %d\n", sizeof(int)); + Serial.printf("long : %d\n", sizeof(long)); + Serial.printf("long long : %d\n", sizeof(long long)); + Serial.printf("bool : %d\n", sizeof(bool)); + Serial.printf("void* : %d\n", sizeof(void *)); +} + +#define TENTIMES(x) do { x; x; x; x; x; x; x; x; x; x; } while (0) +#define FIFTYTIMES(x) do { TENTIMES(x); TENTIMES(x); TENTIMES(x); TENTIMES(x); TENTIMES(x); } while (0) + +#define TIMEIT(name, op, count) do { \ + uint32_t us_end, us_start; \ + us_start = micros(); \ + for (uint8_t i=0; i