From 52541e7ca7aedfe1d962f324e479b1ed2485b67d Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 19 Dec 2024 19:03:30 +0000 Subject: [PATCH] run part one with goroutines re-run benchmarks --- day-19/benchmark | 22 +++++++++++----------- day-19/internal/one/benchmark | 4 ++-- day-19/internal/one/solve.go | 14 +++++++++++--- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/day-19/benchmark b/day-19/benchmark index 303ea75..1506903 100644 --- a/day-19/benchmark +++ b/day-19/benchmark @@ -2,14 +2,14 @@ goos: linux goarch: amd64 pkg: github.com/onyx-and-iris/aoc2024/day-19 cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz -BenchmarkSolve-12 1000000000 0.1996 ns/op -BenchmarkSolve-12 1000000000 0.2115 ns/op -BenchmarkSolve-12 1000000000 0.1903 ns/op -BenchmarkSolve-12 1000000000 0.1840 ns/op -BenchmarkSolve-12 1000000000 0.1891 ns/op -BenchmarkSolve-12 1000000000 0.1828 ns/op -BenchmarkSolve-12 1000000000 0.1888 ns/op -BenchmarkSolve-12 1000000000 0.1834 ns/op -BenchmarkSolve-12 1000000000 0.1895 ns/op -BenchmarkSolve-12 1000000000 0.1832 ns/op -ok github.com/onyx-and-iris/aoc2024/day-19 24.811s +BenchmarkSolve-12 1000000000 0.09381 ns/op +BenchmarkSolve-12 1000000000 0.1010 ns/op +BenchmarkSolve-12 1000000000 0.1131 ns/op +BenchmarkSolve-12 1000000000 0.09298 ns/op +BenchmarkSolve-12 1000000000 0.09649 ns/op +BenchmarkSolve-12 1000000000 0.09659 ns/op +BenchmarkSolve-12 1000000000 0.1022 ns/op +BenchmarkSolve-12 1000000000 0.09501 ns/op +BenchmarkSolve-12 1000000000 0.09695 ns/op +BenchmarkSolve-12 1000000000 0.1007 ns/op +ok github.com/onyx-and-iris/aoc2024/day-19 9.903s diff --git a/day-19/internal/one/benchmark b/day-19/internal/one/benchmark index bc2a8b5..df43355 100644 --- a/day-19/internal/one/benchmark +++ b/day-19/internal/one/benchmark @@ -2,5 +2,5 @@ goos: linux goarch: amd64 pkg: github.com/onyx-and-iris/aoc2024/day-19/internal/one cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz -BenchmarkSolve-12 1000000000 0.1706 ns/op -ok github.com/onyx-and-iris/aoc2024/day-19/internal/one 2.018s +BenchmarkSolve-12 1000000000 0.08205 ns/op +ok github.com/onyx-and-iris/aoc2024/day-19/internal/one 0.765s diff --git a/day-19/internal/one/solve.go b/day-19/internal/one/solve.go index bc21db8..f1c2397 100644 --- a/day-19/internal/one/solve.go +++ b/day-19/internal/one/solve.go @@ -18,11 +18,19 @@ func Solve(buf []byte) (int, error) { log.Debug(stripes, designs) - var sum int + conc := len(designs) + sumChan := make(chan bool) for _, design := range designs { - ok := isPossibleArrangement(design, stripes) + go func() { + ok := isPossibleArrangement(design, stripes) + sumChan <- ok + }() + } + + var sum int + for range conc { + ok := <-sumChan if ok { - log.Debugf("design: %s is possible", design) sum++ } }