Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Created August 1, 2020 08:08
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 bblanchon/3eb3565cbf52abf73c5732045bc269c0 to your computer and use it in GitHub Desktop.
Save bblanchon/3eb3565cbf52abf73c5732045bc269c0 to your computer and use it in GitHub Desktop.
See ArduinoJson memory usage and speed with string deduplication
#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