Skip to content

Commit

Permalink
Update version and deps (#10)
Browse files Browse the repository at this point in the history
* Update version and deps

* Fix ci

* Fix codeconv
  • Loading branch information
dnovikoff authored Aug 14, 2024
1 parent 70723b6 commit 47e1d7f
Show file tree
Hide file tree
Showing 108 changed files with 3,352 additions and 18,842 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.20
- name: Set up Go 1.22.6
uses: actions/setup-go@v1
with:
go-version: 1.20
go-version: 1.22.6

- name: Check out source code
uses: actions/checkout@v1

- name: Build
env:
GOPROXY: "off"
run: make generate build
run: make build

- name: Test
env:
GOPROXY: "off"
run: make testcover

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
file: ./coverage.txt
fail_ci_if_error: true
verbose: false
fail_ci_if_error: true # optional (default = false)
files: ./coverage.txt
flags: unittests # optional
token: ${{ secrets.CODECOV_TOKEN }} # required
verbose: false # optional (default = false)

19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: generate test build
all: generate test

.PHONY: clean
clean:
Expand All @@ -8,8 +8,8 @@ clean:
gobin:
mkdir -p gobin

gobin/stringer: gobin
go build -mod vendor -o ./gobin/stringer ./vendor/golang.org/x/tools/cmd/stringer
gobin/stringer: gobin go.sum go.mod
GOBIN=$(CURDIR)/gobin go install golang.org/x/tools/cmd/stringer@latest

.PHONY: test
test:
Expand All @@ -23,8 +23,17 @@ testcover:
generate: gobin/stringer
PATH=$(CURDIR)/gobin:$(PATH) go generate -mod vendor ./...

.PHONY: bench
bench:
cd ./examples/bench/ && go test -bench=. -benchtime 5s -benchmem -run notest
# go test -v ./examples/bench/ --benchtime 10000x --bench ./examples/bench/ -benchmem

.PHONY: build
build:
mkdir -p build
GOBIN=$(shell pwd)/build go install -mod vendor ./examples/performance/...
go build -o /dev/null ./...

.PHONY: tidy
tidy:
go mod tidy
go mod vendor
rm -rf build gobin
58 changes: 42 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,52 @@ YakuChankan: 1, YakuPinfu: 1, YakuTsumo: 1
Value: 3.20
```

### Perfomance
There is an `examples/performance` folder with some mesaurement program.
### Benchmarks
Benchmarks are located at `examples/bench`.
I've already made some code improvements, based on profiling for simular test code.
Although there could be more space for improve, the results on my machine seems quite fine to start with.

` go run ./examples/performance/main.go`
`cd ./examples/bench/ && go test -bench=. -benchtime 5s -benchmem -run notest`

Output:
```
================== Test shanten
Repeat: 10000
Elapsed: 255.822276ms
Estemated speed: 39089.637369968514 per second
================== Test tempai
Repeat: 10000
Elapsed: 122.52142ms
Estemated speed: 81618.38150423003 per second
Tempai hand count: 4826
================== Test effectivity
Repeat: 1000
Elapsed: 255.058354ms
Estemated speed: 3920.6714240773313 per second
goos: linux
goarch: amd64
pkg: github.com/dnovikoff/tempai-core/examples/bench
cpu: 12th Gen Intel(R) Core(TM) i7-1260P
BenchmarkShanten-16 419035 13633 ns/op 5924 B/op 29 allocs/op
--- BENCH: BenchmarkShanten-16
bench_test.go:32: Repeat: 1
bench_test.go:33: RPS: 33561.55188615921
bench_test.go:32: Repeat: 100
bench_test.go:33: RPS: 60719.62470414363
bench_test.go:32: Repeat: 10000
bench_test.go:33: RPS: 69839.23838410915
bench_test.go:32: Repeat: 419035
bench_test.go:33: RPS: 73352.4715081205
BenchmarkTempai-16 976167 6007 ns/op 3514 B/op 52 allocs/op
--- BENCH: BenchmarkTempai-16
bench_test.go:58: Repeat: 1
bench_test.go:59: Tempai hand count: 0
bench_test.go:60: RPS: 30308.540946838817
bench_test.go:58: Repeat: 100
bench_test.go:59: Tempai hand count: 48
bench_test.go:60: RPS: 79856.06742407485
bench_test.go:58: Repeat: 10000
bench_test.go:59: Tempai hand count: 4826
bench_test.go:60: RPS: 119202.33090145081
bench_test.go:58: Repeat: 715213
... [output truncated]
BenchmarkEffective-16 48742 123743 ns/op 21308 B/op 315 allocs/op
--- BENCH: BenchmarkEffective-16
bench_test.go:81: Repeat: 1
bench_test.go:82: RPS: 12198.543493906827
bench_test.go:81: Repeat: 100
bench_test.go:82: RPS: 8245.353351732016
bench_test.go:81: Repeat: 10000
bench_test.go:82: RPS: 8123.973175995651
bench_test.go:81: Repeat: 48742
bench_test.go:82: RPS: 8081.242170967126
PASS
ok github.com/dnovikoff/tempai-core/examples/bench 24.435s
```
87 changes: 87 additions & 0 deletions examples/bench/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package bench_test

import (
"math/rand"
"sort"
"testing"

"github.com/dnovikoff/tempai-core/compact"
"github.com/dnovikoff/tempai-core/hand/effective"
"github.com/dnovikoff/tempai-core/hand/shanten"
"github.com/dnovikoff/tempai-core/hand/tempai"
"github.com/dnovikoff/tempai-core/tile"
)

func BenchmarkShanten(b *testing.B) {
repeat := b.N
data := make([]compact.Instances, repeat)
// prepare
source := rand.NewSource(123)
rnd := rand.New(source)
instances := compact.AllInstances().Instances()
for k := range data {
shuffle(rnd, instances)
data[k] = compact.NewInstances().Add(instances[:13])
}
b.ResetTimer()
for _, v := range data {
shanten.Calculate(v)
}

b.StopTimer()
b.Log("Repeat: ", repeat)
b.Log("RPS: ", float64(repeat)/b.Elapsed().Seconds())
}

func BenchmarkTempai(b *testing.B) {
repeat := b.N
data := make([]compact.Instances, repeat)
// prepare
source := rand.NewSource(123)
rnd := rand.New(source)
instances := compact.AllInstancesFromTo(tile.Sou1, tile.Sou9+1).Instances()
for k := range data {
shuffle(rnd, instances)
data[k] = compact.NewInstances().Add(instances[:13])
}
cnt := 0

b.ResetTimer()
for _, v := range data {
r := tempai.Calculate(v)
if r != nil {
cnt++
}
}

b.StopTimer()
b.Log("Repeat: ", repeat)
b.Log("Tempai hand count: ", cnt)
b.Log("RPS: ", float64(repeat)/b.Elapsed().Seconds())
}

func BenchmarkEffective(b *testing.B) {
repeat := b.N
data := make([]compact.Instances, repeat)
// prepare
source := rand.NewSource(123)
rnd := rand.New(source)
instances := compact.AllInstances().Instances()
for k := range data {
shuffle(rnd, instances)
data[k] = compact.NewInstances().Add(instances[:14])
}

b.ResetTimer()
for _, v := range data {
effective.Calculate(v)
}

b.StopTimer()
b.Log("Repeat: ", repeat)
b.Log("RPS: ", float64(repeat)/b.Elapsed().Seconds())
}

func shuffle(r *rand.Rand, x sort.Interface) {
r.Shuffle(x.Len(), func(i, j int) { x.Swap(i, j) })
}
127 changes: 0 additions & 127 deletions examples/performance/main.go

This file was deleted.

13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
module github.com/dnovikoff/tempai-core

go 1.15
go 1.22.6

require (
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/stackerr v0.0.0-20150612192056-c2fcf88613f4
github.com/stretchr/testify v1.6.1
golang.org/x/tools v0.9.1
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 47e1d7f

Please sign in to comment.