From c26cf0efa7daa5116ca0f5d1cebdb750f9b459c7 Mon Sep 17 00:00:00 2001 From: Francesco Laurita Date: Sun, 5 Jun 2016 23:34:03 -0700 Subject: [PATCH] Add support for Jitter measurement --- CMakeLists.txt | 2 +- README.md | 4 +++- SpeedTest.cpp | 22 ++++++++++++++++++++++ SpeedTest.h | 1 + main.cpp | 3 ++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0d7500..89589a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) project(SpeedTest) set (SpeedTest_VERSION_MAJOR 1) -set (SpeedTest_VERSION_MINOR 0) +set (SpeedTest_VERSION_MINOR 1) set (SpeedTest_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}) set (SpeedTest_SYSTEM ${CMAKE_SYSTEM}) diff --git a/README.md b/README.md index 8af7500..557b3c7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ It supports the new (undocumented) raw TCP protocol for better accuracy. 3. Aggressive multi-threading program in order to saturate your bandwidth quickly. -4. Provide a URL to the speedtest.net share results image using option --share +4. Test supported: Ping / Jitter / Download speed / Upload speed. + +5. Provide a URL to the speedtest.net share results image using option --share ## Installation diff --git a/SpeedTest.cpp b/SpeedTest.cpp index 245374d..6ee8e31 100644 --- a/SpeedTest.cpp +++ b/SpeedTest.cpp @@ -149,6 +149,27 @@ const double &SpeedTest::latency() { return mLatency; } +const double SpeedTest::jitter(const ServerInfo &server, const int sample) { + auto client = SpeedTestClient(server); + double current_jitter = 0; + long previous_ms = -1; + if (client.connect()){ + for (int i = 0; i < sample; i++){ + long ms = 0; + if (client.ping(ms)){ + if (previous_ms == -1) { + previous_ms = ms; + } else { + current_jitter += std::abs(previous_ms - ms); + } + } + } + client.close(); + } + + return std::floor(current_jitter / sample); +} + bool SpeedTest::share(const ServerInfo& server, std::string& image_url) { std::stringstream hash; hash << std::setprecision(0) << std::fixed << mLatency @@ -415,3 +436,4 @@ ServerInfo SpeedTest::processServerXMLNode(xmlTextReaderPtr reader) { return ServerInfo(); } + diff --git a/SpeedTest.h b/SpeedTest.h index 9d25b8a..f3f6e12 100644 --- a/SpeedTest.h +++ b/SpeedTest.h @@ -67,6 +67,7 @@ class SpeedTest { const double &latency(); const double downloadSpeed(const ServerInfo& server, const TestConfig& config); const double uploadSpeed(const ServerInfo& server, const TestConfig& config); + const double jitter(const ServerInfo& server, const int sample = 40); bool share(const ServerInfo& server, std::string& image_url); private: static CURL* curl_setup(CURL* curl = nullptr); diff --git a/main.cpp b/main.cpp index 8e7e3c6..e75310e 100644 --- a/main.cpp +++ b/main.cpp @@ -79,7 +79,8 @@ int main(const int argc, const char **argv) { << " by " << serverInfo.sponsor << " (" << serverInfo.distance << " km from you): " << sp.latency() << " ms" << std::endl; - + std::cout << "Ping: " << sp.latency() << " ms." << std::endl; + std::cout << "Jitter: " << std::flush << sp.jitter(serverInfo) << " ms." << std::endl; if (latency_only) return EXIT_SUCCESS;