Skip to content

Slowness compared to calling cjpeg directly #45

Description

@rikonor

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions