-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (74 loc) · 1.62 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"advent_of_code_2023/jour1"
"advent_of_code_2023/jour2"
"advent_of_code_2023/jour3"
"advent_of_code_2023/jour4"
"advent_of_code_2023/jour5"
"advent_of_code_2023/jour6"
"advent_of_code_2023/utils"
"fmt"
"os"
"strconv"
"time"
)
func printAnswer(mess string, startTime time.Time) {
fmt.Printf("The answer is :\n%s\n", mess)
fmt.Printf("It took %s to run today's solution\n", time.Since(startTime))
}
func mesureAnswers(iterations int, function func() string) {
var smallestTime time.Duration
for i := 0; i < iterations-1; i++ {
startTime := time.Now()
for j := 0; j < 1000; j++ {
function()
}
newDuration := time.Since(startTime)
if smallestTime > newDuration || smallestTime == 0 {
smallestTime = newDuration
}
}
fmt.Printf("The smallest time to run this day's solution is : %s", smallestTime)
}
func main() {
args := os.Args
if len(args) != 2 {
fmt.Fprintln(os.Stderr, "Please enter one day selection")
return
}
day, err := strconv.Atoi(args[1])
utils.CheckErr(err, "Please enter a number for the day selection")
startTime := time.Now()
switch day {
case 1:
{
answer, err := jour1.Main()
utils.CheckErr(err, "")
printAnswer(answer, startTime)
}
case 2:
{
printAnswer(jour2.Main(), startTime)
}
case 3:
{
printAnswer(jour3.Main(), startTime)
mesureAnswers(3, jour3.Main)
}
case 4:
{
printAnswer(jour4.Main(), startTime)
mesureAnswers(3, jour4.Main)
}
case 5:
{
printAnswer(jour5.Main(), startTime)
// mesureAnswers(3, jour5.Main)
}
case 6:
{
printAnswer(jour6.Main(), startTime)
// mesureAnswers(3, jour5.Main)
}
}
}