Below is example illustrate the above approach:
downloadSize = 5616998;
downloadImgSrc.src = userImageLink;
"time start: "
timeDuration = (end_time - time_start) / 1000;
loadedBits = downloadSize * 8;
bps = (loadedBits / timeDuration).toFixed(2);
speedInKbps = (bps / 1024).toFixed(2);
speedInMbps = (speedInKbps / 1024).toFixed(2);
"Your internet connection speed is: \n"
+ bps +
+ speedInMbps +