-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
105 lines (86 loc) · 2.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"context"
"fmt"
"os"
"runtime"
"sync/atomic"
"time"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
lxr "github.com/pegnet/LXRHash"
"github.com/shirou/gopsutil/mem"
)
var lx lxr.LXRHash
var opr []byte
func runtest(miners int) {
running := true
done := make(chan int, miners)
var hashes uint64
start := time.Now()
for i := 0; i < miners; i++ {
go func(id int) {
n := newninc(id)
for running {
lx.Hash(append(opr, n.Nonce...))
atomic.AddUint64(&hashes, 1)
n.next()
}
done <- 1
}(i)
}
for i := 0; i < 60; i++ {
fmt.Printf("Running 60 second test with %d miners: %ds", miners, i)
time.Sleep(time.Second)
fmt.Print("\r")
}
fmt.Println()
percent, _ := cpu.Percent(0, true)
running = false
dur := time.Since(start)
total := hashes
for i := 0; i < miners; i++ {
<-done
}
rate := float64(total) / dur.Seconds()
fmt.Println("Finished test in", dur)
fmt.Printf("%15s:", "CPU Usage")
for idx, prct := range percent {
fmt.Printf("[%d: %.2f] ", idx, prct)
}
fmt.Println()
fmt.Printf("%15s: %d\n", "Total hashes", total)
fmt.Printf("%15s: %d\n", "Total hashrate", int(rate))
fmt.Printf("%15s: %d\n", "Per miner", int(rate/float64(miners)))
fmt.Println("=====================================")
}
func main() {
fmt.Printf("Benchmarking LXR Hash\n")
fmt.Println("=====================================")
lx.Verbose(true)
lx.Init(lxr.Seed, lxr.MapSizeBits, lxr.HashSize, lxr.Passes)
opr = lx.Hash([]byte("foo"))
fmt.Printf("%10s = %x, %d, %d, %d\n", "Hash Init", lxr.Seed, lxr.MapSizeBits, lxr.HashSize, lxr.Passes)
ctx := context.Background()
to, cancel := context.WithTimeout(ctx, time.Second*5)
defer cancel()
c, err := cpu.InfoWithContext(to)
if err != nil {
fmt.Println("There was an error querying the CPU info. Please try again.")
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("%10s = %s\n", "CPU", c[0].ModelName)
cores := runtime.NumCPU()
fmt.Printf("%10s = %d\n", "Cores", cores)
v, _ := mem.VirtualMemory()
fmt.Printf("%10s = %d MB\n", "Total RAM", v.Total/1024/1024)
h, _ := host.Info()
fmt.Printf("%10s = %s\n", "OS", h.OS)
fmt.Printf("%10s = %s\n", "Platform", h.Platform)
fmt.Println("=====================================")
runtest(1)
if cores > 1 {
runtest(cores)
}
}