Created
June 21, 2021 10:04
-
-
Save bblanchon/1ddbd7f37a254ba2378c3beb5af535b5 to your computer and use it in GitHub Desktop.
ArduinoJson measure deserialization speed
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
// 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); | |
} |
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
// 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