go-libjpeg
go-libjpeg copied to clipboard
Slowness compared to calling cjpeg directly
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!
Hello @rikonor,
were you ever able to find an explanation or even solution to the issue mentioned here? :)
Cheers
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.