- Sat Apr 25, 2015 1:17 am
#15565
I have added a pull request which has shown to remove a large amount of latency from WifiClient.
https://github.com/esp8266/Arduino/pull/111/filesDiscussed here:
viewtopic.php?f=28&t=2672Also, the benchmarks need to consider things like printing a float.
.println( 123.4567f, 4 ); This function prints the int part, then the decimal, then each of the numbers making up the fraction part are printed one character at a time, lastly a \r\n is printed. My example here would require 7 calls to .write() which is also 7 calls to tcp_write().
As you guys have seen, its better to concatenate a string before printing. If you would like to use the formatting features of the Print library, my output buffering class will help.
You can specify a buffer size and it will do everything for you. If you are finished with the buffer before it goes out of scope (like using a global instead of local variable), you can simply call flush() to push the remaining contents. It works with any Arduino library that inherits Print.
Code: Select all/***
Written by Christopher Andrews
MIT licence.
***/
template< unsigned length >
class BufferedPrint : public Print{
public:
using Print::write;
BufferedPrint( Print &output ) : output( output ), cursor( 0x00 ) {}
~BufferedPrint() { flush(); }
void flush(){
if( cursor ) output.write( buffer, cursor );
cursor = 0x00;
}
size_t write( const byte *buffer, size_t size ){
size_t count = size;
while( count-- ) write( *buffer++ );
return size;
}
size_t write( byte data ){
if( cursor == length ) flush();
buffer[ cursor++ ] = data;
return 0x01;
}
protected:
Print &output;
byte buffer[ length ];
uint16_t cursor;
};
//============================================================
BufferedPrint< 150 > buffer( Serial );
void setup(){
Serial.begin( 9600 );
}
void loop(){
buffer.println( "hi, this is a test block of text, you should see it appear in chunks!" );
delay( 500 );
}