add benchmarks for one and two

This commit is contained in:
onyx-and-iris 2024-12-02 02:06:26 +00:00
parent d05828154e
commit 84312b157c
8 changed files with 72 additions and 42 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
*.dll
*.so
*.dylib
bin/
# Test binary, built with `go test -c`
*.test

View File

@ -0,0 +1,6 @@
goos: linux
goarch: amd64
pkg: github.com/onyx-and-iris/aoc2024/day-01/internal/one
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkMain-12 1000000000 0.0006628 ns/op
ok github.com/onyx-and-iris/aoc2024/day-01/internal/one 0.009s

View File

@ -1,11 +1,15 @@
package main
package one
import (
_ "embed"
"os"
"testing"
)
//go:embed testdata/input.txt
var data []byte
func BenchmarkMain(b *testing.B) {
os.Stdout, _ = os.Open(os.DevNull)
main()
Solve(data)
}

View File

@ -0,0 +1,6 @@
goos: linux
goarch: amd64
pkg: github.com/onyx-and-iris/aoc2024/day-01/internal/two
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkMain-12 1000000000 0.001179 ns/op
ok github.com/onyx-and-iris/aoc2024/day-01/internal/two 0.011s

View File

@ -0,0 +1,15 @@
package two
import (
_ "embed"
"os"
"testing"
)
//go:embed testdata/input.txt
var data []byte
func BenchmarkMain(b *testing.B) {
os.Stdout, _ = os.Open(os.DevNull)
Solve(data)
}

View File

@ -1,40 +0,0 @@
/********************************************************************************
Advent of Code 2024 - day-01
********************************************************************************/
package main
import (
"embed"
"flag"
"fmt"
"log"
"github.com/onyx-and-iris/aoc2024/day-01/internal/one"
"github.com/onyx-and-iris/aoc2024/day-01/internal/two"
)
//go:embed testdata
var files embed.FS
func main() {
filename := flag.String("f", "input.txt", "input file")
flag.Parse()
data, err := files.ReadFile(fmt.Sprintf("testdata/%s", *filename))
if err != nil {
log.Fatal(err)
}
val, err := one.Solve(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("solution one: %d\n", val)
val, err = two.Solve(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("solution two: %d\n", val)
}

23
day-01/solve.go Normal file
View File

@ -0,0 +1,23 @@
package day01
import (
"fmt"
"log"
"github.com/onyx-and-iris/aoc2024/day-01/internal/one"
"github.com/onyx-and-iris/aoc2024/day-01/internal/two"
)
func Solve(data []byte) {
val, err := one.Solve(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("solution one: %d\n", val)
val, err = two.Solve(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("solution two: %d\n", val)
}

View File

@ -0,0 +1,15 @@
package day01
import (
_ "embed"
"os"
"testing"
)
//go:embed testdata/input.txt
var data []byte
func BenchmarkMain(b *testing.B) {
os.Stdout, _ = os.Open(os.DevNull)
Solve(data)
}