Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slowness compared to calling cjpeg directly #45

Open
rikonor opened this issue Feb 6, 2018 · 2 comments
Open

Slowness compared to calling cjpeg directly #45

rikonor opened this issue Feb 6, 2018 · 2 comments

Comments

@rikonor
Copy link

rikonor commented Feb 6, 2018

Hi,

I'm trying to get up to speed using this library as a wrapper around mozjpeg.

This is possibly due to a misunderstanding on my part... But I noticed that running a Go script which is equivalent to calling cjpeg directly performs worse. Running the following two snippets on this image produces the following results.

package main

import (
	"log"
	"os"

	"github.com/pixiv/go-libjpeg/jpeg"
)

func main() {
	f, err := os.Open("test-1.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	m, err := jpeg.Decode(f, &jpeg.DecoderOptions{})
	if err != nil {
		log.Fatal(err)
	}

	fOut, err := os.Create("test-1.compressed.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer fOut.Close()

	if err := jpeg.Encode(fOut, m, &jpeg.EncoderOptions{Quality: 75}); err != nil {
		log.Fatal(err)
	}
}

root@bf5cf2b9311b:/go/src/tmp# time ./tmp
real    0m3.563s
user    0m3.400s
sys     0m0.100s
root@bf5cf2b9311b:/go/src/tmp# time /opt/mozjpeg/bin/cjpeg -quality 75 test-1.jpg  > test-1.compressed.jpg

real    0m2.391s
user    0m2.300s
sys     0m0.060s

Would appreciate any ideas!

@scaszoo
Copy link

scaszoo commented Feb 21, 2023

Hello @rikonor,

were you ever able to find an explanation or even solution to the issue mentioned here?
:)

Cheers

@rikonor
Copy link
Author

rikonor commented Feb 21, 2023

Hi @scaszoo, I don't recall honestly, as it was quite a while ago, but I think we ended up calling the shell directly from Go instead of using this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants