Skip to content

Commit c935064

Browse files
committed
Add benchmarks for rest
1 parent 48f11b6 commit c935064

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+625
-83
lines changed

Diff for: 2020/1/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package main
22

33
import (
44
"fmt"
5-
. "github.com/vsliouniaev/aoc/util"
5+
u "github.com/vsliouniaev/aoc/util"
66
"sort"
77
)
88

99
var target = 2020
1010

1111
func main() {
12-
fmt.Printf("Part 1: %d\n", part1("2020/1/input"))
13-
fmt.Printf("Part 2: %d\n", part2("2020/1/input"))
12+
fmt.Printf("Part 1: %d\n", part1(u.RelativeFile("2020/1/input")))
13+
fmt.Printf("Part 2: %d\n", part2(u.RelativeFile("2020/1/input")))
1414
}
1515

1616
func part1(file string) int {
1717
// This is a standard interview question, which you can do in one loop with a hashmap (Provided vals are unique)
18-
ints := ReadLinesInts(file)
18+
ints := u.ReadLinesInts(file)
1919
lookup := make(map[int]struct{})
2020
for _, n := range ints {
2121
other := target - n
@@ -37,7 +37,7 @@ func part2(file string) int {
3737
// Then in the sorted list we can fix the first number and look at the next one and the end one
3838
// If the sum at those indexes is too low we need to look for a higher number - move the middle up
3939
// If the sum at those is too high, then we need to move the index of the end down
40-
ints := ReadLinesInts(file)
40+
ints := u.ReadLinesInts(file)
4141
sort.Ints(ints) // Increasing order
4242
for low := 0; low < len(ints); low++ {
4343
mid := low + 1

Diff for: 2020/1/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/10/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
)
88

99
func main() {
10-
fmt.Printf("Part 1: %d\n", part1("2020/10/input"))
11-
fmt.Printf("Part 2: %d\n", part2("2020/10/input")) // 453551299002368
10+
fmt.Printf("Part 1: %d\n", part1(util.RelativeFile("input"))) // 2432
11+
fmt.Printf("Part 2: %d\n", part2(util.RelativeFile("input"))) // 453551299002368
1212
}
1313

1414
func part1(file string) int {

Diff for: 2020/10/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/11/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
)
88

99
func main() {
10-
fmt.Printf("Part 1: %d\n", part1("2020/11/input")) // 2178
11-
fmt.Printf("Part 2: %d\n", part2("2020/11/input")) // 1978
10+
fmt.Printf("Part 1: %d\n", part1(util.RelativeFile("input"))) // 2178
11+
fmt.Printf("Part 2: %d\n", part2(util.RelativeFile("input"))) // 1978
1212
}
1313

1414
const (

Diff for: 2020/11/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/12/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
)
99

1010
func main() {
11-
fmt.Printf("Part 1: %d\n", part1("2020/12/input")) // 582
12-
fmt.Printf("Part 2: %d\n", part2("2020/12/input")) // 52069
11+
fmt.Printf("Part 1: %d\n", part1(u.RelativeFile("input"))) // 582
12+
fmt.Printf("Part 2: %d\n", part2(u.RelativeFile("input"))) // 52069
1313
}
1414

1515
func part1(file string) int {

Diff for: 2020/12/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/13/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
func main() {
14-
fmt.Printf("Part 1: %d\n", part1("2020/13/input")) // 410
15-
fmt.Printf("Part 2: %d\n", part2("2020/13/input")) // 600691418730595
14+
fmt.Printf("Part 1: %d\n", part1(u.RelativeFile("input"))) // 410
15+
fmt.Printf("Part 2: %d\n", part2(u.RelativeFile("input"))) // 600691418730595
1616
}
1717

1818
func part1(file string) int {

Diff for: 2020/13/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/14/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/15/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/16/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/2/main.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package main
22

33
import (
44
"fmt"
5-
. "github.com/vsliouniaev/aoc/util"
5+
u "github.com/vsliouniaev/aoc/util"
66
"strconv"
77
"strings"
88
)
99

1010
func main() {
11-
fmt.Printf("Part 1: %d\n", part1("2020/2/input")) // 383
12-
fmt.Printf("Part 2: %d\n", part2("2020/2/input")) // 272
11+
fmt.Printf("Part 1: %d\n", part1(u.RelativeFile("input"))) // 383
12+
fmt.Printf("Part 2: %d\n", part2(u.RelativeFile("input"))) // 272
1313
}
1414

1515
func part1(file string) int {
1616
corrects := 0
17-
for _, line := range ReadLinesStrings(file) {
17+
for _, line := range u.ReadLinesStrings(file) {
1818
s := strings.Split(line, ": ")
1919
lower, upper, letter := parseCriteria(s[0])
2020
password := s[1]
@@ -33,7 +33,7 @@ func part1(file string) int {
3333

3434
func part2(file string) int {
3535
corrects := 0
36-
for _, line := range ReadLinesStrings(file) {
36+
for _, line := range u.ReadLinesStrings(file) {
3737
s := strings.Split(line, ": ")
3838
lower, upper, letter := parseCriteria(s[0])
3939
lower--
@@ -53,10 +53,10 @@ func parseCriteria(s string) (lower int, upper int, letter rune) {
5353
limits := strings.Split(split[0], "-")
5454
l, err := strconv.ParseInt(limits[0], 10, 64)
5555
lower = int(l)
56-
Check(err)
57-
u, err := strconv.ParseInt(limits[1], 10, 64)
58-
upper = int(u)
59-
Check(err)
56+
u.Check(err)
57+
up, err := strconv.ParseInt(limits[1], 10, 64)
58+
upper = int(up)
59+
u.Check(err)
6060
letter = rune(split[1][0])
6161
return
6262
}

Diff for: 2020/2/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/3/main.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ package main
22

33
import (
44
"fmt"
5-
. "github.com/vsliouniaev/aoc/util"
5+
u "github.com/vsliouniaev/aoc/util"
66
)
77

88
func main() {
9-
fmt.Printf("Part 1: %d\n", part1("2020/3/input")) // 272
10-
fmt.Printf("Part 2: %d\n", part2("2020/3/input")) // 3898725600
11-
9+
fmt.Printf("Part 1: %d\n", part1(u.RelativeFile("input"))) // 272
10+
fmt.Printf("Part 2: %d\n", part2(u.RelativeFile("input"))) // 3898725600
1211
}
1312

1413
func part1(file string) int {
15-
lines := ReadLinesStrings(file)
14+
lines := u.ReadLinesStrings(file)
1615
return countTrees(lines, 3, 1)
1716
}
1817

@@ -33,7 +32,7 @@ func countTrees(lines []string, right, down int) int {
3332
}
3433

3534
func part2(file string) int {
36-
lines := ReadLinesStrings(file)
35+
lines := u.ReadLinesStrings(file)
3736
return countTrees(lines, 1, 1) *
3837
countTrees(lines, 3, 1) *
3938
countTrees(lines, 5, 1) *

Diff for: 2020/3/main_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
u "github.com/vsliouniaev/aoc/util"
5+
"testing"
6+
)
7+
8+
func BenchmarkPart1(t *testing.B) {
9+
for i := 0; i < t.N; i++ {
10+
part1(u.RelativeFile("input"))
11+
}
12+
}
13+
14+
func BenchmarkPart2(t *testing.B) {
15+
for i := 0; i < t.N; i++ {
16+
part2(u.RelativeFile("input"))
17+
}
18+
}

Diff for: 2020/4/main.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ package main
22

33
import (
44
"fmt"
5-
. "github.com/vsliouniaev/aoc/util"
5+
//. "github.com/vsliouniaev/aoc/util"
6+
u "github.com/vsliouniaev/aoc/util"
67
"regexp"
78
"strconv"
89
"strings"
910
)
1011

1112
func main() {
12-
fmt.Printf("Part 1: %d\n", part1("2020/4/input")) // 226
13-
fmt.Printf("Part 2: %d\n", part2("2020/4/input")) // 160
13+
fmt.Printf("Part 1: %d\n", part1(u.RelativeFile("input"))) // 226
14+
fmt.Printf("Part 2: %d\n", part2(u.RelativeFile("input"))) // 160
1415
}
1516

1617
func part1(file string) int {
1718
valids := 0
1819
val := validator()
19-
for _, line := range ReadLinesStrings(file) {
20+
for _, line := range u.ReadLinesStrings(file) {
2021
if line == "" {
2122
if len(val) == 0 {
2223
valids++
@@ -39,7 +40,7 @@ func part1(file string) int {
3940
func part2(file string) int {
4041
valids := 0
4142
passVal := validator()
42-
for _, line := range ReadLinesStrings(file) {
43+
for _, line := range u.ReadLinesStrings(file) {
4344
if line == "" {
4445
if len(passVal) == 0 {
4546
valids++

0 commit comments

Comments
 (0)