Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Created June 21, 2021 10:04
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/1ddbd7f37a254ba2378c3beb5af535b5 to your computer and use it in GitHub Desktop.
Save bblanchon/1ddbd7f37a254ba2378c3beb5af535b5 to your computer and use it in GitHub Desktop.
ArduinoJson measure deserialization speed
// https://github.com/bblanchon/ArduinoJson/issues/1593
#include <ArduinoJson.h>
void setup() {
// Initialize serial port
Serial.begin(115200);
while (!Serial) continue;
}
void loop() {
StaticJsonDocument<1024> doc;
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
unsigned long start = micros();
deserializeJson(doc, json);
unsigned long stop = micros();
Serial.println(stop - start); // about 640µs on UNO
delay(1000);
}
// https://github.com/bblanchon/ArduinoJson/issues/1593
#include <ArduinoJson.h>
void setup() {
// Initialize serial port
Serial.begin(115200);
while (!Serial) continue;
}
void loop() {
if (!Serial.available()) return;
StaticJsonDocument<1024> doc;
unsigned long start = micros();
DeserializationError err = deserializeJson(doc, Serial);
unsigned long stop = micros(); // about 1280µs
Serial.println(err.c_str());
Serial.println(stop - start);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment