--- /dev/null
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "net/http"
+ "strconv"
+ "time"
+)
+
+const (
+ B = 1
+ KiB = 1 << (10 * iota)
+ MiB
+ GiB
+ TiB
+)
+
+var UPLOAD_PATH = "https://speed.cloudflare.com/__up"
+var DOWNLOAD_PATH = "https://speed.cloudflare.com/__down"
+
+func main() {
+ var measurementBytes int64 = 50 * MiB
+ client := &http.Client{}
+ rate := downloadTest(client, measurementBytes)
+ fmt.Printf("B/ms %v\n", rate)
+ r := bytes.NewReader(make([]byte, measurementBytes))
+ rate = uploadTest(client, r)
+ fmt.Printf("B/ms %v\n", rate)
+}
+
+// Returns the rate in bytes / ms
+func downloadTest(client *http.Client, b int64) int64 {
+ var start = time.Now()
+ resp, _ := client.Get(DOWNLOAD_PATH + "?bytes=" + strconv.FormatInt(b, 10))
+ defer resp.Body.Close()
+ _, _ = io.ReadAll(resp.Body)
+ return (b / time.Since(start).Milliseconds())
+}
+
+// Returns the rate in bytes / ms
+func uploadTest(client *http.Client, r *bytes.Reader) int64 {
+ var start = time.Now()
+ resp, _ := client.Post(UPLOAD_PATH, "text/plain;charset=UTF-8", r)
+ defer resp.Body.Close()
+ _, _ = io.ReadAll(resp.Body)
+ return (r.Size() / time.Since(start).Milliseconds())
+}