File tree 6 files changed +91
-5
lines changed
6 files changed +91
-5
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "fmt"
4
5
"os"
6
+ "runtime"
5
7
"testing"
6
8
7
9
"github.com/stretchr/testify/assert"
@@ -27,7 +29,37 @@ func TestFs2Test(t *testing.T) {
27
29
}
28
30
29
31
func TestFs2Input (t * testing.T ) {
30
- f , err := os .Open ("input.txt" )
31
- require .NoError (t , err )
32
- assert .Equal (t , 95059 , fs2 (f ))
32
+ fmt .Println ("Memory usage before allocating nil slices:" )
33
+ PrintMemUsage ()
34
+
35
+ AllocNilSlices (1000000 )
36
+
37
+ fmt .Println ("Memory usage after allocating nil slices:" )
38
+ PrintMemUsage ()
39
+
40
+ AllocEmptySlices (1000000 )
41
+
42
+ fmt .Println ("Memory usage after allocating empty slices:" )
43
+ PrintMemUsage ()
44
+ }
45
+
46
+ func AllocNilSlices (n int ) {
47
+ for i := 0 ; i < n ; i ++ {
48
+ var s []int
49
+ _ = s
50
+ }
51
+ }
52
+
53
+ func AllocEmptySlices (n int ) {
54
+ for i := 0 ; i < n ; i ++ {
55
+ s := make ([]int , 0 )
56
+ _ = s
57
+ }
58
+ }
59
+
60
+ func PrintMemUsage () {
61
+ var m runtime.MemStats
62
+ runtime .ReadMemStats (& m )
63
+ fmt .Printf ("Alloc = %v MiB" , m .Alloc )
64
+ fmt .Println ()
33
65
}
Original file line number Diff line number Diff line change @@ -75,8 +75,8 @@ Stats: Rust (56%), Go (44%)
75
75
* [ Day 22] ( https://adventofcode.com/2022/day/22 ) : [ Go] ( 2022/day22-go/main.go )
76
76
* [ Day 21] ( https://adventofcode.com/2022/day/21 ) : [ Go] ( 2022/day21-go/main.go )
77
77
* [ Day 20] ( https://adventofcode.com/2022/day/20 ) : [ Go] ( 2022/day20-go/main.go )
78
- * [ Day 19] ( https://adventofcode.com/2022/day/19 ) : [ Rust (part 1)] ( 2022/day19-rust/src/lib.rs ) , [ Go (part 1 and 2) ] ( 2022/day19-go/main.go )
79
- * [ Day 18] ( https://adventofcode.com/2022/day/16 ) : [ Rust (part 1)] ( 2022/day18-rust/src/lib.rs ) , [ Go (part 1 and 2) ] ( 2022/day18-go/main.go )
78
+ * [ Day 19] ( https://adventofcode.com/2022/day/19 ) : [ Rust (part 1)] ( 2022/day19-rust/src/lib.rs ) , [ Go] ( 2022/day19-go/main.go )
79
+ * [ Day 18] ( https://adventofcode.com/2022/day/16 ) : [ Rust (part 1)] ( 2022/day18-rust/src/lib.rs ) , [ Go] ( 2022/day18-go/main.go )
80
80
* [ Day 17] ( https://adventofcode.com/2022/day/16 ) : [ Go] ( 2022/day17-go/main.go )
81
81
* [ Day 16] ( https://adventofcode.com/2022/day/16 ) : [ Go] ( 2022/day16-go/main.go )
82
82
* [ Day 15] ( https://adventofcode.com/2022/day/15 ) : [ Go] ( 2022/day15-go/main.go )
Original file line number Diff line number Diff line change
1
+ module github.com/teivah/aoc/stats
2
+
3
+ go 1.21.4
4
+
5
+ require github.com/teivah/advent-of-code v1.9.1 // indirect
Original file line number Diff line number Diff line change
1
+ github.com/teivah/advent-of-code v1.9.1 h1:m2U+T1q2x24a37r44cP11nOPQlgNi/M73zmTI1RUCps =
2
+ github.com/teivah/advent-of-code v1.9.1 /go.mod h1:p1BrdH9bL5eXxtTxuLfUSW+jYtq9fYzKhzcpTePbpsw =
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "bufio"
5
+ "fmt"
6
+ "os"
7
+ "strings"
8
+ )
9
+
10
+ const totalStars = 450
11
+
12
+ func main () {
13
+ if err := run (); err != nil {
14
+ panic (err )
15
+ }
16
+ }
17
+
18
+ func run () error {
19
+ f , err := os .Open ("README.md" )
20
+ if err != nil {
21
+ return err
22
+ }
23
+
24
+ stats := map [string ]int {
25
+ "Go" : 0 ,
26
+ "Python" : 0 ,
27
+ "Rust" : 0 ,
28
+ }
29
+ scanner := bufio .NewScanner (f )
30
+ for scanner .Scan () {
31
+ line := scanner .Text ()
32
+
33
+ for language := range stats {
34
+ if strings .Contains (line , fmt .Sprintf ("[%s]" , language )) {
35
+ stats [language ] += 2
36
+ } else if strings .Contains (line , fmt .Sprintf ("[%s " , language )) {
37
+ stats [language ] += 1
38
+ }
39
+ }
40
+ }
41
+
42
+ for language , count := range stats {
43
+ fmt .Printf ("%s: %.2f%%\n " , language , float64 (count )/ float64 (totalStars )* 100 )
44
+ }
45
+ return nil
46
+ }
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ gen LANGUAGE YEAR DAY:
40
40
idea {{ YEAR}} / day{{ DAY}} -{{ LANGUAGE}}
41
41
42
42
stats :
43
+ go run cmd/ stats.go
43
44
echo " Go lines: $(find . -name '*.go' -exec cat {} + | wc -l)"
44
45
echo " Go lines without tests: $(find . -name '*.go' ! -name '*_test.go' -exec cat {} + | wc -l)"
45
46
echo " Rust lines: $(find . -name '*.rs' ! -name '*_test.go' -exec cat {} + | wc -l)"
You can’t perform that action at this time.
0 commit comments