Last active
June 13, 2021 23:23
-
-
Save nobonobo/a88370102866117bc67599751bd5fafb to your computer and use it in GitHub Desktop.
GZIPの作成速度C版とGo標準との比較
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"compress/gzip" | |
"io" | |
"os" | |
"testing" | |
"github.com/mistsys/cgzip" | |
) | |
const ( | |
level = 6 | |
src = "alpine-rpi-3.13.4-aarch64.tar" | |
dst = "alpine-rpi-3.13.4-aarch64.tar.gz" | |
) | |
func BenchmarkCGipWriter(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
fp, err := os.Open(src) | |
if err != nil { | |
b.Error(err) | |
} | |
w, err := cgzip.NewWriterLevel(io.Discard, level) | |
if err != nil { | |
b.Error(err) | |
} | |
io.Copy(w, fp) | |
fp.Close() | |
w.Close() | |
} | |
} | |
func BenchmarkStdGipWriter(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
fp, err := os.Open(src) | |
if err != nil { | |
b.Error(err) | |
} | |
w, err := gzip.NewWriterLevel(io.Discard, level) | |
if err != nil { | |
b.Error(err) | |
} | |
io.Copy(w, fp) | |
fp.Close() | |
w.Close() | |
} | |
} | |
func BenchmarkCGipReader(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
fp, err := os.Open(dst) | |
if err != nil { | |
b.Error(err) | |
} | |
r, err := cgzip.NewReader(fp) | |
if err != nil { | |
b.Error(err) | |
} | |
io.Copy(io.Discard, r) | |
fp.Close() | |
r.Close() | |
} | |
} | |
func BenchmarkStdGipReader(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
fp, err := os.Open(dst) | |
if err != nil { | |
b.Error(err) | |
} | |
r, err := gzip.NewReader(fp) | |
if err != nil { | |
b.Error(err) | |
} | |
io.Copy(io.Discard, r) | |
fp.Close() | |
r.Close() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% go test -bench . | |
goos: darwin | |
goarch: amd64 | |
pkg: gzip-perf | |
cpu: Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz | |
BenchmarkCGipWriter-4 1 5414332628 ns/op | |
BenchmarkStdGipWriter-4 1 4237315218 ns/op | |
BenchmarkCGipReader-4 3 444672552 ns/op | |
BenchmarkStdGipReader-4 2 989653348 ns/op | |
PASS | |
ok gzip-perf 15.340s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ちなみにgzipコマンドの場合:
さらに何割か早かったりする。