I am testing the time cost of opening a USB2Serial
port n Centos 7.4. But I found it cost about 7ms for the first time. But it cost much more time in the next opening. If I increase the sleep time, run again, it costs more time except for the first open.
I am using usb2serial
device from FTDI, the kernel driver is ftdi_sio.
Here is my code:
for (int i = 0; i < 10; i++)
{
steady_clock::time_point start = steady_clock::now();
int handle = open("/dev/ttyUSB0", O_RDWR| O_NONBLOCK | O_NDELAY);
steady_clock::time_point end = steady_clock::now();
std::cout << "Item " << i << ":" << " " << duration_cast<std::chrono::nanoseconds>(end-start).count()/1000000 << " ms" << endl;
usleep(10000); // us
close(handle);
}
The result is:
Item 0: 6 ms
Item 1: 76 ms
Item 2: 75 ms
Item 3: 75 ms
Item 4: 75 ms
Item 5: 76 ms
Item 6: 75 ms
Item 7: 75 ms
Item 8: 75 ms
Item 9: 74 ms
I just wonder why the open time becomes longer after the first time. Maybe need some other operation before close.
Anyone has met similar problem ? Or any comments? Thanks