USB Transmission speed

mlu

Well-known member
I have used Paul's USB reception benchmarks https://www.pjrc.com/teensy/benchmark_usb_serial_receive.html for testing a USB device stack, very nice and easy both to understand and to use, and I wonder if there is plans/interest/suggestions for a benchmark that tests Transmission (IN) transfer rates and also response time.

There are quite often folks on the forum that wants to sample loads of ADC's at gazzillion speeds and the send it in real time to a host PC, could alse be Audio or MIDI. So some benchmarks and best practice examples and discussion for good speed might be of interest.
 
Oh, I wrote that benchmark a LONG time ago, back in the Teensy 1.0 days!

You can find the PC-side code at the bottom of this page:

https://www.pjrc.com/teensy/usb_serial.html

Here's the Teensy-side code for use with Arduino:

Code:
// USB Serial Transmit Bandwidth Test
// Written by Paul Stoffregen, paul@pjrc.com
// This benchmark code is in the public domain.
//
// Within 5 seconds of opening the port, this program
// will send a message as rapidly as possible, for 10 seconds.
//
// To run this benchmark test, use serial_read.exe (Windows) or
// serial_listen (Mac, Linux) program can read the data efficiently
// without saving it.
// http://www.pjrc.com/teensy/serial_listen.c
// http://www.pjrc.com/teensy/serial_read.c
// http://www.pjrc.com/teensy/serial_read.exe
//
// You can also run a terminal emulator and select the option
// to capture all text to a file.  However, some terminal emulators
// may limit the speed, depending upon how they update the screen
// and how efficiently their code processes the imcoming data.  The
// Arduino Serial Monitor is particularly slow.  Only use it to
// verify this sketch works.  For actual benchmarks, use the
// efficient receive tests above.
//
// Full disclosure: Paul is the author of Teensyduino. 
//
// Results can vary depending on the number of other USB devices
// connected.  For fastest results, disconnect all others.


//#define USBSERIAL Serial       // for Leonardo, Teensy, Fubarino
#define USBSERIAL SerialUSB  // for Due, Maple

void setup()
{
  USBSERIAL.begin(115200);
}

void loop()
{
  // wait for serial port to be opened
  while (!USBSERIAL) ;

  // give the user 5 seconds to enable text capture in their
  // terminal emulator, or do whatever to get ready
  for (int n=5; n; n--) {
    USBSERIAL.print("10 second speed test begins in ");
    USBSERIAL.print(n);
    USBSERIAL.println(" seconds.");
    if (!USBSERIAL) break;
    delay(1000);
  }

  // send a string as fast as possible, for 10 seconds
  unsigned long beginMillis = millis();
  do {
    USBSERIAL.print("USB Fast Serial Transmit Bandwidth Test, capture this text.\r\n");
  } while (millis() - beginMillis < 10000);
  USBSERIAL.println("done!");

  // after the test, wait forever doing nothing,
  // well, at least until the terminal emulator quits
  while (USBSERIAL) ;
}
 
Somewhere I have a version of this which attempts to also measure the amount of free CPU time which Teensy spends just waiting for the USB.

Except for Teensy 1.0 (which lacked enough USB buffer memory), every Teensy model has been able to transmit at the full USB speed. The differences between them are not how fast they can send, but how little CPU time they consume in doing so.
 
Thanks for the link, yeah with some care and buffer managing good speed can be achievable. Still many struggle to make it happen.
I will play a bit with those benchmarks.
 
Back
Top