Skip to content

Commit 40377b1

Browse files
committed
бенчмарки
1 parent bc911c4 commit 40377b1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

exiv_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,52 @@ func Test_GetBytes_Goroutine(t *testing.T) {
447447
t.Logf("Allocated bytes after test: %+v\n", memStats.HeapAlloc)
448448
}
449449

450+
func BenchmarkImage_GetBytes_KeepAlive(b *testing.B) {
451+
bytes, err := ioutil.ReadFile("testdata/stripped_pixel.jpg")
452+
require.NoError(b, err)
453+
var wg sync.WaitGroup
454+
455+
for i := 0; i < b.N; i++ {
456+
wg.Add(1)
457+
go func() {
458+
defer wg.Done()
459+
460+
img, err := goexiv.OpenBytes(bytes)
461+
require.NoError(b, err)
462+
463+
runtime.GC()
464+
465+
require.NoError(b, img.SetExifString("Exif.Photo.UserComment", "123"))
466+
467+
bytesAfter := img.GetBytes()
468+
assert.NotEmpty(b, bytesAfter)
469+
runtime.KeepAlive(img)
470+
}()
471+
}
472+
473+
wg.Wait()
474+
}
475+
476+
func BenchmarkImage_GetBytes_NoKeepAlive(b *testing.B) {
477+
bytes, err := ioutil.ReadFile("testdata/stripped_pixel.jpg")
478+
require.NoError(b, err)
479+
var wg sync.WaitGroup
480+
481+
for i := 0; i < b.N; i++ {
482+
wg.Add(1)
483+
go func() {
484+
defer wg.Done()
485+
img, err := goexiv.OpenBytes(bytes)
486+
require.NoError(b, err)
487+
488+
require.NoError(b, img.SetExifString("Exif.Photo.UserComment", "123"))
489+
490+
bytesAfter := img.GetBytes()
491+
assert.NotEmpty(b, bytesAfter)
492+
}()
493+
}
494+
}
495+
450496
// Fills the image with metadata
451497
func initializeImage(path string, t *testing.T) {
452498
img, err := goexiv.Open(path)

0 commit comments

Comments
 (0)