Created
August 1, 2020 08:08
-
-
Save bblanchon/3eb3565cbf52abf73c5732045bc269c0 to your computer and use it in GitHub Desktop.
See ArduinoJson memory usage and speed with string deduplication
This file contains 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 <ArduinoJson.h> | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial) continue; | |
StaticJsonDocument<516> doc; | |
const char* json = R"({"list":[{"temperature":21.2,"humidity":68.9,"weather":"overcast clouds"},{"temperature":19.7,"humidity":62.1,"weather":"clear sky"},{"temperature":18.6,"humidity":59.8,"weather":"clear sky"}]})"; | |
unsigned long start = micros(); | |
DeserializationError error = deserializeJson(doc, json); | |
unsigned long stop = micros(); | |
// Test if parsing succeeds. | |
if (error) { | |
Serial.print(F("deserializeJson() failed: ")); | |
Serial.println(error.c_str()); | |
return; | |
} | |
Serial.print("doc.memoryUsage() = "); | |
Serial.println(doc.memoryUsage()); | |
Serial.print("duration = "); | |
Serial.print(stop-start); | |
Serial.println("µs"); | |
} | |
void loop() { | |
// not used in this example | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment