mmfiber / reversi

1 stars 0 forks source link

refactor: separate states from reversi logic #4

Closed mmfiber closed 11 months ago

mmfiber commented 11 months ago

related: #2

web server の機能を追加するにあたって、状態とロジックを切り離す

mmfiber commented 11 months ago

不要なポインタの利用を避けることで、main と比較して100万回heapへの割り当てを減らした. 確保するメモリも半分近くになっている。

~/Documents/Github/reversi main*                                                                              18:46:16
❯ go test -mode=cli  -bench . -benchmem
goos: darwin
goarch: amd64
pkg: reversi
cpu: Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
BenchmarkMain-8            1    4527102618 ns/op    48711840 B/op    2413160 allocs/op
PASS
ok      reversi 4.704s

~/Documents/Github/reversi refactor/separate_logic_and_states*                                            20s 18:43:12
❯ go test -mode=cli  -bench . -benchmem
goos: darwin
goarch: amd64
pkg: reversi
cpu: Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
BenchmarkMain-8            1    4568758925 ns/op    28860944 B/op    1410635 allocs/op
PASS
ok      reversi 4.742s