Skip to content

Instantly share code, notes, and snippets.

@mikkorantalainen
Created August 25, 2020 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikkorantalainen/3eb519670922c12ad2535d984d7cad3a to your computer and use it in GitHub Desktop.
Save mikkorantalainen/3eb519670922c12ad2535d984d7cad3a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Speedtest using speed.cloudflare.com servers
# Copyright 2020 Mikko Rantalainen <mikko.rantalainen@iki.fi>
# License: 2-clause BSD (https://opensource.org/licenses/BSD-2-Clause)
set -e
ID="$RANDOM$RANDOM$RANDOM"
BYTES="${BYTES:=1000000}"
SERVER="https://speed.cloudflare.com"
TEMPFILE="$(tempfile -p speed -s test)"
FORMAT="------------ Statistics: ------------
TCP/IP handshake: %{time_connect} seconds
TLS handshake: %{time_appconnect} seconds
Time until request: %{time_pretransfer} seconds
Request size: %{size_request} bytes
Upload size: %{size_upload} bytes
Upload bandwidth: %{speed_upload} bytes/second
Download size: %{size_download} bytes
Download bandwidth: %{speed_download} bytes/second
HTTP status: %{http_code}
Total time: %{time_total} seconds
"
trap "rm -f -- '$TEMPFILE'" EXIT
echo
echo "Downloading zero bytes from $SERVER ..."
curl --progress-bar -o "$TEMPFILE" "$SERVER/__down?measId=$ID&bytes=0" -w "$FORMAT"
echo
# Store "__cfduid" cookie value
COOKIEVALUE="$(cat "$TEMPFILE")"
echo "Downloading $BYTES bytes from $SERVER ..."
curl --progress-bar -o "$TEMPFILE" "$SERVER/__down?measId=$ID&bytes=$BYTES" -w "$FORMAT"
echo
echo "Uploading $BYTES bytes to $SERVER ..."
curl --progress-bar -F upload=@"$TEMPFILE" -o /dev/null "$SERVER/__up?measId=$ID" -w "$FORMAT"
echo
@mikkorantalainen
Copy link
Author

For example, to test 100 kB file transfers, run

BYTES=100000 ./speedtest-cloudflare

if your shell. The script tests 1 MB file transfers by default. The maximum supported by Cloudflare servers seems to be 500 MB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment