mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
feat(#15): add benchmark tests
This commit is contained in:
parent
16576f49c9
commit
bfe0e700ce
5 changed files with 77 additions and 36 deletions
46
README.md
46
README.md
|
|
@ -42,7 +42,7 @@ The [install script](https://github.com/lovell/sharp/blob/master/preinstall.sh)
|
|||
- Enlarge
|
||||
- Crop
|
||||
- Rotate
|
||||
- Flip
|
||||
- Flip
|
||||
- Thumbnail
|
||||
- Extract area
|
||||
- Format conversion
|
||||
|
|
@ -56,7 +56,19 @@ Here you can see some performance test comparisons for multiple scenarios:
|
|||
- [libvips speed and memory usage](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use)
|
||||
- [sharp performance tests](https://github.com/lovell/sharp#the-task)
|
||||
|
||||
bimg performance tests coming soon!
|
||||
#### bimg performance tests
|
||||
|
||||
Tested using Go 1.4 and libvips-7.42.3 in OSX i7 2.7Ghz
|
||||
```
|
||||
PASS
|
||||
BenchmarkResizeLargeJpeg 30 46652408 ns/op
|
||||
BenchmarkResizePng 20 57387902 ns/op
|
||||
BenchmarkResizeWebP 500 2453220 ns/op
|
||||
BenchmarkConvertToJpeg 30 35556414 ns/op
|
||||
BenchmarkCrop 30 51768475 ns/op
|
||||
BenchmarkExtract 30 50866406 ns/op
|
||||
ok 9.424s
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
|
|
@ -193,6 +205,12 @@ func Resize(buf []byte, o Options) ([]byte, error)
|
|||
func Shutdown()
|
||||
```
|
||||
|
||||
#### func Write
|
||||
|
||||
```go
|
||||
func Write(path string, buf []byte) error
|
||||
```
|
||||
|
||||
#### type Angle
|
||||
|
||||
```go
|
||||
|
|
@ -263,13 +281,13 @@ func (i *Image) Convert(t ImageType) ([]byte, error)
|
|||
#### func (*Image) Crop
|
||||
|
||||
```go
|
||||
func (i *Image) Crop(width int, height int) ([]byte, error)
|
||||
func (i *Image) Crop(width, height int) ([]byte, error)
|
||||
```
|
||||
|
||||
#### func (*Image) Extract
|
||||
|
||||
```go
|
||||
func (i *Image) Extract(top int, left int, width int, height int) ([]byte, error)
|
||||
func (i *Image) Extract(top, left, width, height int) ([]byte, error)
|
||||
```
|
||||
|
||||
#### func (*Image) Flip
|
||||
|
|
@ -278,12 +296,6 @@ func (i *Image) Extract(top int, left int, width int, height int) ([]byte, error
|
|||
func (i *Image) Flip() ([]byte, error)
|
||||
```
|
||||
|
||||
#### func (*Image) Flop
|
||||
|
||||
```go
|
||||
func (i *Image) Flop() ([]byte, error)
|
||||
```
|
||||
|
||||
#### func (*Image) Metadata
|
||||
|
||||
```go
|
||||
|
|
@ -299,7 +311,7 @@ func (i *Image) Process(o Options) ([]byte, error)
|
|||
#### func (*Image) Resize
|
||||
|
||||
```go
|
||||
func (i *Image) Resize(width int, height int) ([]byte, error)
|
||||
func (i *Image) Resize(width, height int) ([]byte, error)
|
||||
```
|
||||
|
||||
#### func (*Image) Rotate
|
||||
|
|
@ -314,6 +326,12 @@ func (i *Image) Rotate(a Angle) ([]byte, error)
|
|||
func (i *Image) Size() (ImageSize, error)
|
||||
```
|
||||
|
||||
#### func (*Image) Thumbnail
|
||||
|
||||
```go
|
||||
func (i *Image) Thumbnail(pixels int) ([]byte, error)
|
||||
```
|
||||
|
||||
#### func (*Image) Type
|
||||
|
||||
```go
|
||||
|
|
@ -325,10 +343,11 @@ func (i *Image) Type() string
|
|||
```go
|
||||
type ImageMetadata struct {
|
||||
Orientation int
|
||||
Channels int
|
||||
Alpha bool
|
||||
Profile bool
|
||||
Space int
|
||||
Type string
|
||||
Space string
|
||||
Size ImageSize
|
||||
}
|
||||
```
|
||||
|
|
@ -407,6 +426,8 @@ func (i Interpolator) String() string
|
|||
type Options struct {
|
||||
Height int
|
||||
Width int
|
||||
AreaHeight int
|
||||
AreaWidth int
|
||||
Top int
|
||||
Left int
|
||||
Crop bool
|
||||
|
|
@ -423,6 +444,7 @@ type Options struct {
|
|||
}
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT - Tomas Aparicio
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ type ImageMetadata struct {
|
|||
Size ImageSize
|
||||
}
|
||||
|
||||
// Get the image size by width and height pixels
|
||||
func Size(buf []byte) (ImageSize, error) {
|
||||
metadata, err := Metadata(buf)
|
||||
if err != nil {
|
||||
|
|
@ -33,6 +34,7 @@ func Size(buf []byte) (ImageSize, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Extract the image metadata (size, type, alpha channel, profile, EXIF orientation...)
|
||||
func Metadata(buf []byte) (ImageMetadata, error) {
|
||||
defer C.vips_thread_shutdown()
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ func TestResizePngWithTransparency(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func benchmarkResize(file string, o Options, b *testing.B) {
|
||||
func runBenchmarkResize(file string, o Options, b *testing.B) {
|
||||
buf, _ := Read(path.Join("fixtures", file))
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
|
|
@ -147,7 +147,7 @@ func BenchmarkResizeLargeJpeg(b *testing.B) {
|
|||
Width: 800,
|
||||
Height: 600,
|
||||
}
|
||||
benchmarkResize("test.jpg", options, b)
|
||||
runBenchmarkResize("test.jpg", options, b)
|
||||
}
|
||||
|
||||
func BenchmarkResizePng(b *testing.B) {
|
||||
|
|
@ -155,7 +155,7 @@ func BenchmarkResizePng(b *testing.B) {
|
|||
Width: 200,
|
||||
Height: 200,
|
||||
}
|
||||
benchmarkResize("test.png", options, b)
|
||||
runBenchmarkResize("test.png", options, b)
|
||||
}
|
||||
|
||||
func BenchmarkResizeWebP(b *testing.B) {
|
||||
|
|
@ -163,5 +163,29 @@ func BenchmarkResizeWebP(b *testing.B) {
|
|||
Width: 200,
|
||||
Height: 200,
|
||||
}
|
||||
benchmarkResize("test.webp", options, b)
|
||||
runBenchmarkResize("test.webp", options, b)
|
||||
}
|
||||
|
||||
func BenchmarkConvertToJpeg(b *testing.B) {
|
||||
options := Options{Type: JPEG}
|
||||
runBenchmarkResize("test.png", options, b)
|
||||
}
|
||||
|
||||
func BenchmarkCrop(b *testing.B) {
|
||||
options := Options{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
Crop: true,
|
||||
}
|
||||
runBenchmarkResize("test.jpg", options, b)
|
||||
}
|
||||
|
||||
func BenchmarkExtract(b *testing.B) {
|
||||
options := Options{
|
||||
Top: 100,
|
||||
Left: 50,
|
||||
AreaWidth: 600,
|
||||
AreaHeight: 480,
|
||||
}
|
||||
runBenchmarkResize("test.jpg", options, b)
|
||||
}
|
||||
|
|
|
|||
22
type.go
22
type.go
|
|
@ -11,14 +11,27 @@ const (
|
|||
MAGICK
|
||||
)
|
||||
|
||||
// Determines the image type format (jpeg, png, webp or tiff)
|
||||
func DetermineImageType(buf []byte) ImageType {
|
||||
return vipsImageType(buf)
|
||||
}
|
||||
|
||||
// Determines the image type format by name (jpeg, png, webp or tiff)
|
||||
func DetermineImageTypeName(buf []byte) string {
|
||||
return getImageTypeName(vipsImageType(buf))
|
||||
}
|
||||
|
||||
// Check if a given image type is supported
|
||||
func IsTypeSupported(t ImageType) bool {
|
||||
return t == JPEG || t == PNG || t == WEBP
|
||||
}
|
||||
|
||||
// Check if a given image type name is supported
|
||||
func IsTypeNameSupported(t string) bool {
|
||||
return t == "jpeg" || t == "jpg" ||
|
||||
t == "png" || t == "webp"
|
||||
}
|
||||
|
||||
func getImageTypeName(code ImageType) string {
|
||||
imageType := "unknown"
|
||||
|
||||
|
|
@ -42,12 +55,3 @@ func getImageTypeName(code ImageType) string {
|
|||
|
||||
return imageType
|
||||
}
|
||||
|
||||
func IsTypeSupported(t ImageType) bool {
|
||||
return t == JPEG || t == PNG || t == WEBP
|
||||
}
|
||||
|
||||
func IsTypeNameSupported(t string) bool {
|
||||
return t == "jpeg" || t == "jpg" ||
|
||||
t == "png" || t == "webp"
|
||||
}
|
||||
|
|
|
|||
11
vips.h
11
vips.h
|
|
@ -11,12 +11,6 @@ enum types {
|
|||
MAGICK
|
||||
};
|
||||
|
||||
void
|
||||
vips_malloc_cb(VipsObject *object, char *buf)
|
||||
{
|
||||
g_free(buf);
|
||||
};
|
||||
|
||||
int
|
||||
vips_affine_interpolator(VipsImage *in, VipsImage **out, double a, double b, double c, double d, VipsInterpolate *interpolator)
|
||||
{
|
||||
|
|
@ -157,10 +151,5 @@ vips_init_image(void *buf, size_t len, int imageType, VipsImage **out) {
|
|||
#endif
|
||||
}
|
||||
|
||||
// Listen for "postclose" signal to delete input buffer
|
||||
//if (out != NULL) {
|
||||
//g_signal_connect(out, "postclose", G_CALLBACK(vips_malloc_cb), buf);
|
||||
//}
|
||||
|
||||
return code;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue