Added a logging system to show home much time it
took to do a certain part of the program
This commit is contained in:
parent
42cc4f8717
commit
144d3c2aed
@ -4,6 +4,7 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"maze-solver/utils"
|
||||
"os"
|
||||
|
||||
"golang.org/x/image/draw"
|
||||
@ -16,6 +17,7 @@ type ImageReader struct {
|
||||
}
|
||||
|
||||
func (r *ImageReader) Read() (*RawMaze, error) {
|
||||
defer utils.Timer("Image reader", 3)()
|
||||
image, err := r.getShrunkImage()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -11,6 +11,7 @@ type StringsReader struct {
|
||||
}
|
||||
|
||||
func (r *StringsReader) Read() (*RawMaze, error) {
|
||||
defer utils.Timer("Strings Reader", 3)()
|
||||
width, height := len((*r.Lines)[0]), len(*r.Lines)
|
||||
ret := &RawMaze{
|
||||
Width: width,
|
||||
|
@ -2,6 +2,7 @@ package reader
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"maze-solver/utils"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -11,6 +12,7 @@ type TextReader struct {
|
||||
}
|
||||
|
||||
func (r TextReader) Read() (*RawMaze, error) {
|
||||
defer utils.Timer("Text Reader", 3)()
|
||||
lines, err := getLines(r.Filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"maze-solver/maze"
|
||||
"maze-solver/utils"
|
||||
"os"
|
||||
|
||||
"github.com/mazznoer/colorgrad"
|
||||
@ -22,6 +23,7 @@ type ImageWriter struct {
|
||||
}
|
||||
|
||||
func (w *ImageWriter) Write() error {
|
||||
defer utils.Timer("Image writer", 3)()
|
||||
if w.Filename[len(w.Filename)-4:] != ".png" {
|
||||
return errors.New("Filename of ImageWriter doesn't have .png extension. The only suppported image type is png")
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"maze-solver/maze"
|
||||
"maze-solver/utils"
|
||||
)
|
||||
|
||||
type StringsWriter struct {
|
||||
@ -14,6 +15,7 @@ type StringsWriter struct {
|
||||
}
|
||||
|
||||
func (w *StringsWriter) Write() error {
|
||||
defer utils.Timer("Strings writer", 3)()
|
||||
w.lines = make([][]byte, w.Maze.Height)
|
||||
|
||||
// Fill the lines with walls
|
||||
|
@ -1,8 +1,10 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
@ -27,3 +29,14 @@ func AssertEqual[T comparable](t *testing.T, got T, want T, msg string, args ...
|
||||
t.Fatalf(msg+"\nGot: %v, Want: %v", args...)
|
||||
}
|
||||
}
|
||||
|
||||
var VERBOSE_LEVEL int
|
||||
|
||||
func Timer(msg string, level int) func() {
|
||||
start := time.Now()
|
||||
return func() {
|
||||
if level <= VERBOSE_LEVEL {
|
||||
fmt.Printf("%-19s %12v\n", msg, time.Since(start))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user