From c5778049462f7fba2c90db316956091a67d93515 Mon Sep 17 00:00:00 2001 From: potassium5703 Date: Tue, 3 Sep 2024 23:07:15 +0300 Subject: [PATCH] concat test --- concat_test.go | 24 ++++++++++++++++++++++++ genprof | 2 +- scale_test.go | 14 -------------- util.go | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 concat_test.go create mode 100644 util.go diff --git a/concat_test.go b/concat_test.go new file mode 100644 index 0000000..d551b43 --- /dev/null +++ b/concat_test.go @@ -0,0 +1,24 @@ +package imageutils + +import ( + "image" + "image/png" + "io" + "testing" +) + +func BenchmarkConcat(b *testing.B) { + var instance image.Image + pixel := SinglePixel{} + + for i := 0; i < b.N; i++ { + instance = Concat(instance, pixel, Right) + } + err := png.Encode( + io.Discard, + instance, + ) + if err != nil { + panic(err) + } +} diff --git a/genprof b/genprof index 0780930..0871ece 100755 --- a/genprof +++ b/genprof @@ -1,2 +1,2 @@ -go test -cpuprofile=profile.out -bench=BenchmarkSinglePixel && +go test -cpuprofile=profile.out -bench=$1 && go tool pprof -text profile.out diff --git a/scale_test.go b/scale_test.go index 740b702..63afb00 100644 --- a/scale_test.go +++ b/scale_test.go @@ -18,20 +18,6 @@ func Render(img image.Image, rect image.Rectangle) image.Image { return newimg } -type SinglePixel struct{} - -func (s SinglePixel) At(x, y int) color.Color { - return color.White -} - -func (s SinglePixel) ColorModel() color.Model { - return color.RGBAModel -} - -func (s SinglePixel) Bounds() image.Rectangle { - return image.Rect(0, 0, 1, 1) -} - func BenchmarkScale(b *testing.B) { for i := 0; i < b.N; i++ { err := png.Encode(io.Discard, diff --git a/util.go b/util.go new file mode 100644 index 0000000..516178a --- /dev/null +++ b/util.go @@ -0,0 +1,20 @@ +package imageutils + +import ( + "image" + "image/color" +) + +type SinglePixel struct{} + +func (s SinglePixel) At(x, y int) color.Color { + return color.White +} + +func (s SinglePixel) ColorModel() color.Model { + return color.RGBAModel +} + +func (s SinglePixel) Bounds() image.Rectangle { + return image.Rect(0, 0, 1, 1) +}