34 unsigned int next_fibonacci (
const bool clear =
false);
36 unsigned int run_buffered (
const int iterations);
38 unsigned int run_static_buffered (
const int iterations);
40 unsigned int run_unbuffered (
const int iterations);
50 unsigned int dynamicBuffer, staticBuffer, noBuffer;
52 pwOut <<
"PropWare::StringBuilder Demo\n";
53 pwOut <<
"============================\n";
57 pwIn.
input_prompt(
"How many iterations of the fibonacci sequency would you like to see?\n>>> ",
61 dynamicBuffer = run_buffered(iterations);
62 pwOut <<
"Total runtime was " << dynamicBuffer <<
"us using the PropWare::StringBuilder class\n";
65 pwOut <<
"\nLet's try this again, but static initialization (no use of malloc).\n";
69 staticBuffer = run_static_buffered(iterations);
70 pwOut <<
"Total runtime was " << staticBuffer <<
"us using the PropWare::StaticStringBuilder class\n";
73 pwOut <<
"\nFinally, let's try this without any buffering.\n";
77 noBuffer = run_unbuffered(iterations);
78 pwOut <<
"Total runtime was " << noBuffer <<
"us without buffering\n";
82 pwOut <<
"\tDynamic buffer: " << dynamicBuffer <<
" us\n";
83 pwOut <<
"\tStatic buffer: " << staticBuffer <<
" us\n";
84 pwOut <<
"\tUnbuffered: " << noBuffer <<
" us\n";
85 pwOut <<
"Take note that using a buffer won't help you increase your runtime performance.\n";
90 unsigned int run_buffered (
const int iterations) {
91 const volatile unsigned int timerStart = CNT;
94 const Printer stringStream(&
string);
95 for (
int i = 0; i < iterations; ++i) {
96 stringStream << next_fibonacci();
97 if (i != iterations - 1)
101 pwOut <<
string.to_string() <<
'\n';
105 unsigned int run_static_buffered (
const int iterations) {
106 const volatile unsigned int timerStart = CNT;
110 const Printer stringStream(&
string);
111 for (
int i = 0; i < iterations; ++i) {
112 stringStream << next_fibonacci();
113 if (i != iterations - 1)
114 stringStream <<
", ";
117 pwOut <<
string.to_string() <<
'\n';
121 unsigned int run_unbuffered (
const int iterations) {
122 const volatile unsigned int timerStart = CNT;
123 for (
int i = 0; i < iterations; ++i) {
124 pwOut << next_fibonacci();
125 if (i != iterations - 1)
132 unsigned int next_fibonacci (
const bool clear) {
133 static unsigned int next = 1;
134 static unsigned previous = 1;
140 const unsigned int retVal = next;
Generic definitions and functions for the Parallax Propeller.
const PropWare::NonNegativeIntegerComparator NON_NEGATIVE_COMP
Global instance for shared use by PropWare applications.
const PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
Build a dynamically-sized string in RAM using the PropWare::Printer interface.
void input_prompt(const char prompt[], const char failureResponse[], char userInput[], const size_t bufferLength, const Comparator< char > &comparator)
Prompt the user for input and store the value only if it is sanitized.
Container class that has formatting methods for human-readable output. This class can be constructed ...
static uint32_t measure_time_interval(const register uint32_t start)
Determine the number of microseconds passed since a starting point.
Build a statically-sized string in RAM using the PropWare::Printer interface.
void println(const char string[]) const
Print a null-terminated string followed by a newline (' ')