Skip to content

Instantly share code, notes, and snippets.

@ronen-e
Last active June 10, 2016 21:42
Show Gist options
  • Select an option

  • Save ronen-e/db8bcb756e5dfabbe99d39d4f6650fc6 to your computer and use it in GitHub Desktop.

Select an option

Save ronen-e/db8bcb756e5dfabbe99d39d4f6650fc6 to your computer and use it in GitHub Desktop.
Calculate resource download time
/**
* Returns download time from server
*
* @param {number} cwnd - Initial Congestion Window size
* @param {number} rtt - Roundtrip Time in Milliseconds
* @param {number} packetSize - Packet Size in Bytes
* @param {number} totalSize - Total Transfer Size in Bytes
* @return {number} time - Download Time in Milliseconds
*/
function downloadTime(cwnd, rtt, packetSize, totalSize) {
var segments = totalSize / packetSize;
return rtt * Math.ceil( Math.log2(segments / cwnd) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment