Skip to content

Commit

Permalink
Add support for Jitter measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
taganaka committed Jun 6, 2016
1 parent 20b5bec commit c26cf0e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions SpeedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -415,3 +436,4 @@ ServerInfo SpeedTest::processServerXMLNode(xmlTextReaderPtr reader) {
return ServerInfo();
}


1 change: 1 addition & 0 deletions SpeedTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c26cf0e

Please sign in to comment.