Skip to content

Commit

Permalink
update lxrhash, less dependence on channels
Browse files Browse the repository at this point in the history
  • Loading branch information
WhoSoup committed Oct 31, 2019
1 parent fb20ddc commit b599d77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.12
require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/pegnet/LXRHash v0.0.0-20190806215027-2c3ac3baf00d
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/pegnet/LXRHash v0.0.0-20191028162532-138fe8d191a2
github.com/shirou/gopsutil v2.19.9+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ github.com/pegnet/LXRHash v0.0.0-20190729193922-452b32b2d231 h1:/kqjIK3ufejdrpUw
github.com/pegnet/LXRHash v0.0.0-20190729193922-452b32b2d231/go.mod h1:0zBp9GFy9F77zuQbPkAmdUBRiptMaJ1V96eVFdMnXZA=
github.com/pegnet/LXRHash v0.0.0-20190806215027-2c3ac3baf00d h1:zE0clII5SVvyUqGdQ6prCL555kItIRbjrdNX+TJxgJg=
github.com/pegnet/LXRHash v0.0.0-20190806215027-2c3ac3baf00d/go.mod h1:0zBp9GFy9F77zuQbPkAmdUBRiptMaJ1V96eVFdMnXZA=
github.com/pegnet/LXRHash v0.0.0-20190826135050-107c3df7dfcf h1:ywy3f036ywnSt8LfBlR2sALoFHkf3fw+QF6P++/FzxQ=
github.com/pegnet/LXRHash v0.0.0-20190826135050-107c3df7dfcf/go.mod h1:0zBp9GFy9F77zuQbPkAmdUBRiptMaJ1V96eVFdMnXZA=
github.com/pegnet/LXRHash v0.0.0-20191028162532-138fe8d191a2 h1:ec8NDi02ydYYKw/RpzFZypAh8rvyxZAvkeVVDBo+lxA=
github.com/pegnet/LXRHash v0.0.0-20191028162532-138fe8d191a2/go.mod h1:0zBp9GFy9F77zuQbPkAmdUBRiptMaJ1V96eVFdMnXZA=
github.com/pegnet/OracleRecord v0.0.2/go.mod h1:VrY7Shn4oSCli47CsUYBFjH68IenGYtnLaXaaivepu4=
github.com/pegnet/pegnet v0.0.2/go.mod h1:FUyEs8fyLOzPXZgyqXcqiOhQi58loNtujykIbxxoKbQ=
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v2.19.9+incompatible h1:IrPVlK4nfwW10DF7pW+7YJKws9NkgNzWozwwWv9FsgY=
github.com/shirou/gopsutil v2.19.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/zpatrick/go-config v0.0.0-20190509173111-460869022dbd/go.mod h1:N7O1arBXMtrvgkF3kTwZdytK4gsAf13kfqv9Z6vk47Q=
Expand Down
41 changes: 17 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"runtime"
"sync/atomic"
"time"

"github.com/shirou/gopsutil/cpu"
Expand All @@ -19,32 +20,24 @@ var opr []byte

func runtest(miners int) {

stoppers := make([]chan bool, miners)
for i := range stoppers {
stoppers[i] = make(chan bool, 1)
}
running := true
done := make(chan int, miners)

results := make(chan int, miners)
var hashes uint64

start := time.Now()
for i := 0; i < miners; i++ {
go func(id int) {
hashes := 0
n := newninc(id)
for {
select {
case <-stoppers[id]:
results <- hashes
return
default:
}

for running {
lx.Hash(append(opr, n.Nonce...))
hashes++
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)
Expand All @@ -53,15 +46,14 @@ func runtest(miners int) {
fmt.Println()

percent, _ := cpu.Percent(0, true)
for _, s := range stoppers {
s <- true
}
running = false
dur := time.Since(start)
total := hashes

total := 0
for i := 0; i < miners; i++ {
total += <-results
<-done
}
dur := time.Since(start)

rate := float64(total) / dur.Seconds()
fmt.Println("Finished test in", dur)
fmt.Printf("%15s:", "CPU Usage")
Expand All @@ -85,7 +77,7 @@ func main() {

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*3)
to, cancel := context.WithTimeout(ctx, time.Second*5)
defer cancel()
c, err := cpu.InfoWithContext(to)
if err != nil {
Expand All @@ -106,7 +98,8 @@ func main() {
fmt.Printf("%10s = %s\n", "Platform", h.Platform)
fmt.Println("=====================================")

for i := 1; i <= cores+2; i++ {
runtest(i)
runtest(1)
if cores > 1 {
runtest(cores)
}
}

0 comments on commit b599d77

Please sign in to comment.