~dricottone/image2ascii

c47680932d916c44022c7059bb84f010caea60bf — qeesung 6 years ago 97d2c5a
Add ScaleImage and Image2ASCII benchmark
2 files changed, 64 insertions(+), 3 deletions(-)

M convert/convert_test.go
M convert/resize_test.go
M convert/convert_test.go => convert/convert_test.go +25 -0
@@ 92,3 92,28 @@ func TestImageFile2ASCIIString(t *testing.T) {
		})
	}
}


func BenchmarkBigImage2ASCIIMatrix(b *testing.B) {
	convertOptions := DefaultOptions
	convertOptions.FitScreen = false
	convertOptions.Colored = false
	convertOptions.ExpectedWidth = 200
	convertOptions.ExpectedHeight = 200

	for i:=0; i< b.N; i++ {
		_ = ImageFile2ASCIIMatrix("testdata/cat_2000x1500.jpg", &convertOptions)
	}
}

func BenchmarkSmallImage2ASCIIMatrix(b *testing.B) {
	convertOptions := DefaultOptions
	convertOptions.FitScreen = false
	convertOptions.Colored = false
	convertOptions.ExpectedWidth = 200
	convertOptions.ExpectedHeight = 200

	for i:=0; i< b.N; i++ {
		_ = ImageFile2ASCIIMatrix("testdata/husky_200x200.jpg", &convertOptions)
	}
}

M convert/resize_test.go => convert/resize_test.go +39 -3
@@ 142,13 142,12 @@ func TestScaleToFitTerminalSize(t *testing.T) {
	}
}


// ExampleScaleImage is scale image example
func ExampleScaleImage() {
	imageFilePath := "testdata/cat_2000x1500.jpg"
	img, err := OpenImageFile(imageFilePath)
	if err != nil {
		log.Fatal("open image file "+imageFilePath + " failed")
		log.Fatal("open image file " + imageFilePath + " failed")
	}

	options := DefaultOptions


@@ 160,4 159,41 @@ func ExampleScaleImage() {
	sz := scaledImage.Bounds()
	fmt.Print(sz.Max.X, sz.Max.Y)
	// output: 200 100
}
\ No newline at end of file
}

// BenchmarkScaleImage benchmark scale image test scale image
func BenchmarkScaleBigImage(b *testing.B) {
	imageFilePath := "testdata/cat_2000x1500.jpg"
	img, err := OpenImageFile(imageFilePath)
	if err != nil {
		log.Fatalf("Open image file %s failed", imageFilePath)
	}

	options := DefaultOptions
	options.Colored = false
	options.FitScreen = false
	options.ExpectedHeight = 100
	options.ExpectedWidth = 100

	for i := 0; i < b.N; i++ {
		_ = ScaleImage(img, &options)
	}
}

func BenchmarkScaleSmallImage(b *testing.B) {
	imageFilePath := "testdata/husky_200x200.jpg"
	img, err := OpenImageFile(imageFilePath)
	if err != nil {
		log.Fatalf("Open image file %s failed : %s", imageFilePath, err.Error())
	}

	options := DefaultOptions
	options.Colored = false
	options.FitScreen = false
	options.ExpectedHeight = 100
	options.ExpectedWidth = 100

	for i := 0; i < b.N; i++ {
		_ = ScaleImage(img, &options)
	}
}