Created
April 18, 2020 15:57
-
-
Save Tasssadar/5da40232f79224c9c98b70c6ac90f3d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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