aboutsummaryrefslogtreecommitdiff
path: root/internal/speed
diff options
context:
space:
mode:
Diffstat (limited to 'internal/speed')
-rw-r--r--internal/speed/cpuinfo.go54
-rw-r--r--internal/speed/speed.go10
2 files changed, 64 insertions, 0 deletions
diff --git a/internal/speed/cpuinfo.go b/internal/speed/cpuinfo.go
new file mode 100644
index 0000000..09e7a89
--- /dev/null
+++ b/internal/speed/cpuinfo.go
@@ -0,0 +1,54 @@
+package speed
+
+import (
+ "io/ioutil"
+ "os"
+ "runtime"
+ "strings"
+)
+
+// cpuModelName returns the "model name" acc. to /proc/cpuinfo, or ""
+// on error.
+//
+// Examples: On my desktop PC:
+//
+// $ grep "model name" /proc/cpuinfo
+// model name : Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
+//
+// --> Returns "Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz".
+//
+// On a Raspberry Pi 4:
+//
+// $ grep "model name" /proc/cpuinfo
+// (empty)
+// $ grep Hardware /proc/cpuinfo
+// Hardware : BCM2835
+//
+// --> Returns "BCM2835"
+func cpuModelName() string {
+ if runtime.GOOS != "linux" {
+ return ""
+ }
+ f, err := os.Open("/proc/cpuinfo")
+ if err != nil {
+ return ""
+ }
+ content, err := ioutil.ReadAll(f)
+ if err != nil {
+ return ""
+ }
+ lines := strings.Split(string(content), "\n")
+ // Look for "model name", then for "Hardware" (arm devices don't have "model name")
+ for _, want := range []string{"model name", "Hardware"} {
+ for _, line := range lines {
+ if strings.HasPrefix(line, want) {
+ parts := strings.SplitN(line, ":", 2)
+ if len(parts) != 2 {
+ continue
+ }
+ return strings.TrimSpace(parts[1])
+ }
+ }
+ }
+ return ""
+}
diff --git a/internal/speed/speed.go b/internal/speed/speed.go
index 231a982..0b1a51a 100644
--- a/internal/speed/speed.go
+++ b/internal/speed/speed.go
@@ -27,6 +27,16 @@ const blockSize = 4096
// Run - run the speed the test and print the results.
func Run() {
+ cpu := cpuModelName()
+ if cpu == "" {
+ cpu = "unknown"
+ }
+ aes := "; no AES acceleration"
+ if stupidgcm.CpuHasAES() {
+ aes = "; with AES acceleration"
+ }
+ fmt.Printf("cpu: %s%s\n", cpu, aes)
+
bTable := []struct {
name string
f func(*testing.B)