pixiv / go-libjpeg

An implementation of Go binding for libjpeg (or libjpeg-turbo).
BSD 3-Clause "New" or "Revised" License
157 stars 52 forks source link

Slowness compared to calling cjpeg directly #45

Open rikonor opened 6 years ago

rikonor commented 6 years ago

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 commented 1 year ago

Hello @rikonor,

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

Cheers

rikonor commented 1 year ago

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.