return early if total exceeds target

re-run benchmarks
This commit is contained in:
onyx-and-iris 2024-12-07 23:47:20 +00:00
parent d42df0cd84
commit 9bfd45aee4
5 changed files with 22 additions and 14 deletions

View File

@ -2,14 +2,14 @@ goos: linux
goarch: amd64
pkg: github.com/onyx-and-iris/aoc2024/day-07
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkSolve-12 1000000000 0.2486 ns/op
BenchmarkSolve-12 1000000000 0.2670 ns/op
BenchmarkSolve-12 1000000000 0.2498 ns/op
BenchmarkSolve-12 1000000000 0.2449 ns/op
BenchmarkSolve-12 1000000000 0.2520 ns/op
BenchmarkSolve-12 1000000000 0.2512 ns/op
BenchmarkSolve-12 1000000000 0.2500 ns/op
BenchmarkSolve-12 1000000000 0.2494 ns/op
BenchmarkSolve-12 1000000000 0.2473 ns/op
BenchmarkSolve-12 1000000000 0.2453 ns/op
ok github.com/onyx-and-iris/aoc2024/day-07 37.477s
BenchmarkSolve-12 1000000000 0.1503 ns/op
BenchmarkSolve-12 1000000000 0.1498 ns/op
BenchmarkSolve-12 1000000000 0.1577 ns/op
BenchmarkSolve-12 1000000000 0.1621 ns/op
BenchmarkSolve-12 1000000000 0.1490 ns/op
BenchmarkSolve-12 1000000000 0.1437 ns/op
BenchmarkSolve-12 1000000000 0.1566 ns/op
BenchmarkSolve-12 1000000000 0.1508 ns/op
BenchmarkSolve-12 1000000000 0.1465 ns/op
BenchmarkSolve-12 1000000000 0.1468 ns/op
ok github.com/onyx-and-iris/aoc2024/day-07 18.051s

View File

@ -2,5 +2,5 @@ goos: linux
goarch: amd64
pkg: github.com/onyx-and-iris/aoc2024/day-07/internal/one
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkSolve-12 1000000000 0.001456 ns/op
BenchmarkSolve-12 1000000000 0.001262 ns/op
ok github.com/onyx-and-iris/aoc2024/day-07/internal/one 0.017s

View File

@ -37,6 +37,10 @@ func Solve(buf []byte) (int, error) {
}
func next(target int, operands []int, total int, operator string) (int, bool) {
if total > target {
return 0, false
}
if len(operands) == 0 {
if total == target {
log.Debug(total)

View File

@ -2,5 +2,5 @@ goos: linux
goarch: amd64
pkg: github.com/onyx-and-iris/aoc2024/day-07/internal/two
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkSolve-12 1000000000 0.2539 ns/op
ok github.com/onyx-and-iris/aoc2024/day-07/internal/two 3.822s
BenchmarkSolve-12 1000000000 0.1525 ns/op
ok github.com/onyx-and-iris/aoc2024/day-07/internal/two 1.642s

View File

@ -38,6 +38,10 @@ func Solve(buf []byte) (int, error) {
}
func next(target int, operands []int, total int, operator string) (int, bool) {
if total > target {
return 0, false
}
if len(operands) == 0 {
if total == target {
log.Debug(total)