-
Notifications
You must be signed in to change notification settings - Fork 20
/
miner.go
77 lines (60 loc) · 2.04 KB
/
miner.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
package main
import "fmt"
import "time"
import "crypto/rand"
import "sync"
import "flag"
import "runtime"
import "github.com/shirou/gopsutil/cpu"
import "github.com/deroproject/astrobwt"
func main() {
fmt.Printf("DERO AstroBWT Miner v0.01 alpha\n")
info, _ := cpu.Info()
fmt.Printf("CPU: %s PhysicalThreads:%d\n", info[0].ModelName, len(info))
threads_ptr := flag.Int("threads", runtime.NumCPU(), "No. Of threads")
iterations_ptr := flag.Int("iterations", 100, "No. Of DERO Stereo POW calculated/thread")
bench_ptr := flag.Bool("bench", true, "run bench with params")
flag.Parse()
var wg sync.WaitGroup
threads := *threads_ptr
iterations := *iterations_ptr
if threads < 1 || iterations < 1 || threads > 2048 {
fmt.Printf("Invalid parameters\n")
return
}
if *bench_ptr {
fmt.Printf("%20s %20s %20s %20s %20s \n", "Threads", "Total Time", "Total Iterations", "Time/PoW ","Hash Rate/Sec")
for bench := 1; bench <= threads; bench++ {
now := time.Now()
for i := 0; i < bench; i++ {
wg.Add(1)
go random_execution(&wg, iterations)
}
wg.Wait()
duration := time.Now().Sub(now)
fmt.Printf("%20s %20s %20s %20s %20s \n", fmt.Sprintf("%d", bench), fmt.Sprintf("%s", duration), fmt.Sprintf("%d", bench*iterations),
fmt.Sprintf("%s", duration/time.Duration(bench*iterations)),fmt.Sprintf("%.1f", float32(time.Second)/ (float32(duration/time.Duration(bench*iterations)))) )
}
} else {
fmt.Printf("Starting %d threads\n", threads)
now := time.Now()
for i := 0; i < threads; i++ {
wg.Add(1)
go random_execution(&wg, iterations)
}
wg.Wait()
duration := time.Now().Sub(now)
fmt.Printf("Total iterations %d ( per thread %d)\n", threads*iterations, iterations)
fmt.Printf("Total time %s\n", duration)
fmt.Printf("time per PoW (avg) %s\n", duration/time.Duration(threads*iterations))
}
}
func random_execution(wg *sync.WaitGroup, iterations int) {
var workbuf [255]byte
for i := 0; i < iterations; i++ {
rand.Read(workbuf[:])
//astrobwt.POW(workbuf[:])
astrobwt.POW_0alloc(workbuf[:])
}
wg.Done()
}