mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 23:25:33 +00:00
use elapsedTime for calculation
This commit is contained in:
@ -42,8 +42,6 @@ using namespace rtc;
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
using chrono::duration_cast;
|
|
||||||
using chrono::microseconds;
|
|
||||||
using chrono::milliseconds;
|
using chrono::milliseconds;
|
||||||
using chrono::steady_clock;
|
using chrono::steady_clock;
|
||||||
|
|
||||||
@ -262,13 +260,13 @@ int main(int argc, char **argv) try {
|
|||||||
printCounter++;
|
printCounter++;
|
||||||
|
|
||||||
if (enableThroughputSet) {
|
if (enableThroughputSet) {
|
||||||
float dataCountMultiplier =
|
const double elapsedTimeInMs =
|
||||||
duration_cast<microseconds>((steady_clock::now() - stepTime)).count() /
|
std::chrono::duration<double>(steady_clock::now() - stepTime).count() * 1000.0;
|
||||||
(1000.0 * stepDurationInMs);
|
|
||||||
|
|
||||||
stepTime = steady_clock::now();
|
stepTime = steady_clock::now();
|
||||||
|
|
||||||
int byteToSendThisLoop = static_cast<int>(byteToSendOnEveryLoop * dataCountMultiplier);
|
int byteToSendThisLoop =
|
||||||
|
static_cast<int>(byteToSendOnEveryLoop * (elapsedTimeInMs / stepDurationInMs));
|
||||||
|
|
||||||
binary tempMessageData(byteToSendThisLoop);
|
binary tempMessageData(byteToSendThisLoop);
|
||||||
fill(tempMessageData.begin(), tempMessageData.end(), std::byte(0xFF));
|
fill(tempMessageData.begin(), tempMessageData.end(), std::byte(0xFF));
|
||||||
@ -282,15 +280,14 @@ int main(int argc, char **argv) try {
|
|||||||
if (printCounter >= STEP_COUNT_FOR_1_SEC) {
|
if (printCounter >= STEP_COUNT_FOR_1_SEC) {
|
||||||
unsigned long _receivedSize = receivedSize.exchange(0);
|
unsigned long _receivedSize = receivedSize.exchange(0);
|
||||||
unsigned long _sentSize = sentSize.exchange(0);
|
unsigned long _sentSize = sentSize.exchange(0);
|
||||||
float dataCountMultiplier =
|
const double elapsedTimeInSec =
|
||||||
duration_cast<milliseconds>((steady_clock::now() - printTime)).count() /
|
std::chrono::duration<double>(steady_clock::now() - printTime).count();
|
||||||
(1000.0); // sec
|
|
||||||
printTime = steady_clock::now();
|
printTime = steady_clock::now();
|
||||||
|
|
||||||
cout << "#" << i / STEP_COUNT_FOR_1_SEC
|
cout << "#" << i / STEP_COUNT_FOR_1_SEC
|
||||||
<< " Received: " << static_cast<int>(_receivedSize / (dataCountMultiplier * 1000))
|
<< " Received: " << static_cast<int>(_receivedSize / (elapsedTimeInSec * 1000))
|
||||||
<< " KB/s"
|
<< " KB/s"
|
||||||
<< " Sent: " << static_cast<int>(_sentSize / (dataCountMultiplier * 1000))
|
<< " Sent: " << static_cast<int>(_sentSize / (elapsedTimeInSec * 1000))
|
||||||
<< " KB/s"
|
<< " KB/s"
|
||||||
<< " BufferSize: " << dc->bufferedAmount() << endl;
|
<< " BufferSize: " << dc->bufferedAmount() << endl;
|
||||||
printStatCounter++;
|
printStatCounter++;
|
||||||
@ -388,14 +385,14 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
float dataCountMultiplier =
|
const double elapsedTimeInMs =
|
||||||
duration_cast<microseconds>((steady_clock::now() - stepTime)).count() /
|
std::chrono::duration<double>(steady_clock::now() - stepTime).count() *
|
||||||
(1000.0 * stepDurationInMs);
|
1000.0;
|
||||||
|
|
||||||
stepTime = steady_clock::now();
|
stepTime = steady_clock::now();
|
||||||
|
|
||||||
int byteToSendThisLoop =
|
int byteToSendThisLoop = static_cast<int>(
|
||||||
static_cast<int>(byteToSendOnEveryLoop * dataCountMultiplier);
|
byteToSendOnEveryLoop * (elapsedTimeInMs / stepDurationInMs));
|
||||||
|
|
||||||
binary tempMessageData(byteToSendThisLoop);
|
binary tempMessageData(byteToSendThisLoop);
|
||||||
fill(tempMessageData.begin(), tempMessageData.end(), std::byte(0xFF));
|
fill(tempMessageData.begin(), tempMessageData.end(), std::byte(0xFF));
|
||||||
|
Reference in New Issue
Block a user