Skip to content

Commit 954e973

Browse files
authored
Decimal places at jitter and ping. (#48)
* Update README.md ups * stdout for --csv-header and --version Changed output type to stdout for --version and --csv-header. Addition to "send --json and --csv results to stdout and logs to stderr #39" * decimal places at jitter and ping better values with --share The browser version doesn't really seem to use decimal places at ping but this limits/extended ping and jitter to .2 decimal places at --csv / --json and stdout. this prevent 1.0909090909090908 ping times within csv and json and extend those values in rest of the data. The ping value could be adjusted to .0 to match the web version but this way the values are more accurate. +1 for the cli. * Update README.md Formatting adjusted
1 parent c2af01b commit 954e973

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ For Linux users, you can use either the archive from golang.org, or install from
4242
```shell script
4343
# pacman -S go
4444
```
45-
45+
4646
2. Then, clone the repository:
4747

4848
```shell script
@@ -59,10 +59,10 @@ can now proceed to build `librespeed-cli` with the build script:
5959
6060
If you want to build for another operating system or system architecture, use the `GOOS` and `GOARCH` environment
6161
variables. Run `go tool dist list` to get a list of possible combinations of `GOOS` and `GOARCH`.
62-
62+
6363
Note: Technically, the CLI can be compiled with older Go versions that support Go modules, with `GO111MODULE=on`
6464
set. If you're compiling with an older Go runtime, you might have to change the Go version in `go.mod`.
65-
65+
6666
```shell script
6767
# Let's say we're building for 64-bit Windows on Linux
6868
$ GOOS=windows GOARCH=amd64 ./build.sh
@@ -74,7 +74,7 @@ can now proceed to build `librespeed-cli` with the build script:
7474
$ ls out
7575
librespeed-cli-windows-amd64.exe
7676
```
77-
77+
7878
5. Now you can use the `librespeed-cli` and test your Internet speed!
7979

8080
## Install from AUR
@@ -145,15 +145,15 @@ GLOBAL OPTIONS:
145145
multiple times. Cannot be used with --server
146146
--server-json value Use an alternative server list from remote JSON file
147147
--local-json value Use an alternative server list from local JSON file,
148-
or read from stdin with "--local-json -".
148+
or read from stdin with "--local-json -".
149149
--source SOURCE SOURCE IP address to bind to
150150
--timeout TIMEOUT HTTP TIMEOUT in seconds. (default: 15)
151151
--duration value Upload and download test duration in seconds (default: 15)
152152
--chunks value Chunks to download from server, chunk size depends on server configuration (default: 100)
153153
--upload-size value Size of payload being uploaded in KiB (default: 1024)
154154
--secure Use HTTPS instead of HTTP when communicating with
155155
LibreSpeed.org operated servers (default: false)
156-
--skip-cert-verify Skip verifying SSL certificate for HTTPS connections (self-signed certs) (default: false)
156+
--skip-cert-verify Skip verifying SSL certificate for HTTPS connections (self-signed certs) (default: false)
157157
--no-pre-allocate Do not pre allocate upload data. Pre allocation is
158158
enabled by default to improve upload performance. To
159159
support systems with insufficient memory, use this
@@ -205,7 +205,7 @@ As you can see in the example, all servers have their schemes defined. In case o
205205
`librespeed-cli` will use `http` by default, or `https` when the `--secure` option is enabled.
206206
207207
## Use a custom telemetry server
208-
By default, the telemetry result will be sent to `librespeed.org`. You can also customize your telemetry settings
208+
By default, the telemetry result will be sent to `librespeed.org`. You can also customize your telemetry settings
209209
via the `--telemetry` prefixed options. In order to load a custom telemetry endpoint configuration, you'll have to use the
210210
`--telemetry-json` option to specify a local JSON file containing the configuration bits. The format is as below:
211211

speedtest/helper.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func doSpeedTest(c *cli.Context, servers []defs.Server, telemetryServer defs.Tel
7979
}
8080

8181
if pb != nil {
82-
pb.FinalMSG = fmt.Sprintf("Ping: %.0f ms\tJitter: %.0f ms\n", p, jitter)
82+
pb.FinalMSG = fmt.Sprintf("Ping: %.2f ms\tJitter: %.2f ms\n", p, jitter)
8383
pb.Stop()
8484
}
8585

@@ -117,9 +117,9 @@ func doSpeedTest(c *cli.Context, servers []defs.Server, telemetryServer defs.Tel
117117
if c.Bool(defs.OptionSimple) {
118118
if c.Bool(defs.OptionBytes) {
119119
useMebi := c.Bool(defs.OptionMebiBytes)
120-
log.Warnf("Ping:\t%.0f ms\tJitter:\t%.0f ms\nDownload rate:\t%s\nUpload rate:\t%s", p, jitter, humanizeMbps(downloadValue, useMebi), humanizeMbps(uploadValue, useMebi))
120+
log.Warnf("Ping:\t%.2f ms\tJitter:\t%.2f ms\nDownload rate:\t%s\nUpload rate:\t%s", p, jitter, humanizeMbps(downloadValue, useMebi), humanizeMbps(uploadValue, useMebi))
121121
} else {
122-
log.Warnf("Ping:\t%.0f ms\tJitter:\t%.0f ms\nDownload rate:\t%.2f Mbps\nUpload rate:\t%.2f Mbps", p, jitter, downloadValue, uploadValue)
122+
log.Warnf("Ping:\t%.2f ms\tJitter:\t%.2f ms\nDownload rate:\t%.2f Mbps\nUpload rate:\t%.2f Mbps", p, jitter, downloadValue, uploadValue)
123123
}
124124
}
125125

@@ -149,7 +149,7 @@ func doSpeedTest(c *cli.Context, servers []defs.Server, telemetryServer defs.Tel
149149

150150
rep.Name = currentServer.Name
151151
rep.Address = u.String()
152-
rep.Ping = p
152+
rep.Ping = math.Round(p*100) / 100
153153
rep.Jitter = math.Round(jitter*100) / 100
154154
rep.Download = math.Round(downloadValue*100) / 100
155155
rep.Upload = math.Round(uploadValue*100) / 100
@@ -162,7 +162,7 @@ func doSpeedTest(c *cli.Context, servers []defs.Server, telemetryServer defs.Tel
162162
var rep report.JSONReport
163163
rep.Timestamp = time.Now()
164164

165-
rep.Ping = p
165+
rep.Ping = math.Round(p*100) / 100
166166
rep.Jitter = math.Round(jitter*100) / 100
167167
rep.Download = math.Round(downloadValue*100) / 100
168168
rep.Upload = math.Round(uploadValue*100) / 100
@@ -175,15 +175,15 @@ func doSpeedTest(c *cli.Context, servers []defs.Server, telemetryServer defs.Tel
175175

176176
rep.Client = report.Client{ispInfo.RawISPInfo}
177177
rep.Client.Readme = ""
178-
179-
reps_json = append(reps_json,rep)
178+
179+
reps_json = append(reps_json, rep)
180180
}
181181
} else {
182182
log.Infof("Selected server %s (%s) is not responding at the moment, try again later", currentServer.Name, u.Hostname())
183183
}
184184

185185
//add a new line after each test if testing multiple servers
186-
if ( len(servers) > 1 && !silent){
186+
if len(servers) > 1 && !silent {
187187
log.Warn()
188188
}
189189
}
@@ -240,15 +240,15 @@ func sendTelemetry(telemetryServer defs.TelemetryServer, ispInfo *defs.GetIPResu
240240
if fPing, err := wr.CreateFormField("ping"); err != nil {
241241
log.Debugf("Error creating form field: %s", err)
242242
return "", err
243-
} else if _, err = fPing.Write([]byte(strconv.Itoa(int(pingVal)))); err != nil {
243+
} else if _, err = fPing.Write([]byte(strconv.FormatFloat(pingVal, 'f', 2, 64))); err != nil {
244244
log.Debugf("Error writing form field: %s", err)
245245
return "", err
246246
}
247247

248248
if fJitter, err := wr.CreateFormField("jitter"); err != nil {
249249
log.Debugf("Error creating form field: %s", err)
250250
return "", err
251-
} else if _, err = fJitter.Write([]byte(strconv.Itoa(int(jitter)))); err != nil {
251+
} else if _, err = fJitter.Write([]byte(strconv.FormatFloat(jitter, 'f', 2, 64))); err != nil {
252252
log.Debugf("Error writing form field: %s", err)
253253
return "", err
254254
}

speedtest/speedtest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func SpeedTest(c *cli.Context) error {
6464

6565
// print version
6666
if c.Bool(defs.OptionVersion) {
67+
log.SetOutput(os.Stdout)
6768
log.Warnf("%s %s (built on %s)", defs.ProgName, defs.ProgVersion, defs.BuildDate)
6869
log.Warn("https://github.com/librespeed/speedtest-cli")
6970
log.Warn("Licensed under GNU Lesser General Public License v3.0")
@@ -80,7 +81,7 @@ func SpeedTest(c *cli.Context) error {
8081
if c.Bool(defs.OptionCSVHeader) {
8182
var rep []report.CSVReport
8283
b, _ := gocsv.MarshalBytes(&rep)
83-
log.Warnf("%s", b)
84+
os.Stdout.WriteString(string(b))
8485
return nil
8586
}
8687

0 commit comments

Comments
 (0)