Skip to content

Instantly share code, notes, and snippets.

@Tasssadar
Created April 18, 2020 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tasssadar/5da40232f79224c9c98b70c6ac90f3d1 to your computer and use it in GitHub Desktop.
Save Tasssadar/5da40232f79224c9c98b70c6ac90f3d1 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <FreeRTOS.h>
#include <sstream>
#include <mutex>
//static std::mutex m;
template <typename T>
void testPrintf(void *fmt)
{
const auto s1 = uxTaskGetStackHighWaterMark(NULL);
{
char buf[16];
snprintf(buf, sizeof(buf), (const char *)fmt, (T)xTaskGetTickCount());
}
const auto s2 = uxTaskGetStackHighWaterMark(NULL);
printf("printf %s: %d B\n", (const char *)fmt, s1 - s2);
while (1)
{
sleep(1);
}
vTaskDelete(NULL);
}
template <typename T>
void testStringStream(void *fmt)
{
const auto s1 = uxTaskGetStackHighWaterMark(NULL);
{
//m.lock();
std::ostringstream ss;
//m.unlock();
ss << (T)xTaskGetTickCount();
}
const auto s2 = uxTaskGetStackHighWaterMark(NULL);
printf("sstream %s: %d B\n", (const char *)fmt, s1 - s2);
vTaskDelete(NULL);
}
void setup()
{
// put your setup code here, to run once:
sleep(1);
xTaskCreate(testPrintf<int>, "", 4096, (void *)"%d", 1, NULL);
xTaskCreate(testPrintf<long long>, "", 4096, (void *)"%lld", 1, NULL);
xTaskCreate(testPrintf<double>, "", 4096, (void *)"%f", 1, NULL);
xTaskCreate(testPrintf<double>, "", 4096, (void *)"%.4f", 1, NULL);
xTaskCreate(testStringStream<int>, "", 4096, (void *)"%d", 1, NULL);
usleep(100000);
xTaskCreate(testStringStream<long long>, "", 4096, (void *)"%lld", 1, NULL);
usleep(100000);
xTaskCreate(testStringStream<double>, "", 4096, (void *)"%f", 1, NULL);
while (1)
sleep(1);
}
void loop()
{
// put your main code here, to run repeatedly:
}
/*
printf %d: 1072 B
printf %.4f: 1332 B
printf %lld: 928 B
printf %f: 1332 B
sstream %d: 948 B
sstream %lld: 1012 B
sstream %f: 2052 B
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment