zip gzip 7z 简单比较

zip gzip 7z 简单比较_第1张图片

 

 

待压缩文件: 线上服务日志文件:

    $ du -h logs
    1.2G    logs/41
    1.2G    logs/42
    2.3G    logs
 

zip压缩:

    $ time zip -r -9 -v logs.zip logs

        省略输出
    
    total bytes=2410353994, compressed=257652922 -> 89% savings

    real    1m58.479s
    user    1m53.171s
    sys     0m4.124s
 

gzip压缩:

 gzip压缩分两步,tar打单一文件是第一步,使用gzip压缩是第二步

   第一步,tar归档单一文件:

       $ time tar -cvf logs.tar logs

             省略输出

       real    0m11.745s
       user    0m0.250s
       sys     0m5.327s

  第二步,gzip压缩:

    $ time gzip -9 -v logs.tar
    logs.tar:        89.3% -- replaced with logs.tar.gz

    real    1m59.562s
    user    1m54.171s
    sys     0m3.077s
 

7z压缩:

    $ time 7z a -bb3 -mx9 -r logs.7z logs/*

    7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

    Scanning the drive:
    2 folders, 210 files, 2410353994 bytes (2299 MiB)

    Creating archive: logs.7z

    Add new data to archive: 2 folders, 210 files, 2410353994 bytes (2299 MiB)

        省略输出

    Files read from disk: 210
    Archive size: 64929090 bytes (62 MiB)
    Everything is Ok

    real    7m57.902s
    user    0m0.031s
    sys     0m0.093s
 

对比:

    zip 压缩率:89% 时间:1m58.479s                             约为2分钟           从 2.3GB -> 246MB

    gzip 压缩率:89% 时间:0m11.745s + 1m59.562s     约为 2分钟10秒   从  2.3GB -> 246MB

    7z 压缩率:97% 时间: 7m57.902s                             约为8分钟           从 2.3GB -> 62MB

 

签于7z 使用 -mx9 压缩时间太长,现进行以下几种 -mx压缩级别测试

========   -mx1

$ time 7z a -bb0 -mx1 -r logs.7z logs/

Add new data to archive: 6 folders, 212 files, 2410354342 bytes (2299 MiB)


Files read from disk: 212
Archive size: 185024061 bytes (177 MiB)
Everything is Ok

real    0m22.096s
user    0m0.015s
sys     0m0.078s


========   -mx2

$ time 7z a -bb0 -mx2 -r logs.7z logs/

Add new data to archive: 6 folders, 212 files, 2410354342 bytes (2299 MiB)


Files read from disk: 212
Archive size: 168550502 bytes (161 MiB)
Everything is Ok

real    0m26.624s
user    0m0.015s
sys     0m0.093s
 

========   -mx3

$ time 7z a -bb0 -mx3 -r logs.7z logs/

Add new data to archive: 6 folders, 212 files, 2410354342 bytes (2299 MiB)


Files read from disk: 212
Archive size: 147696095 bytes (141 MiB)
Everything is Ok

real    0m29.046s
user    0m0.000s
sys     0m0.078s

========   -mx4

$ time 7z a -bb0 -mx4 -r logs.7z logs/

Add new data to archive: 6 folders, 212 files, 2410354342 bytes (2299 MiB)


Files read from disk: 212
Archive size: 117705771 bytes (113 MiB)
Everything is Ok

real    0m35.351s
user    0m0.015s
sys     0m0.140s

========   -mx5

$ time 7z a -bb0 -mx5 -r logs.7z logs/

Add new data to archive: 6 folders, 212 files, 2410354342 bytes (2299 MiB)


Files read from disk: 212
Archive size: 77937349 bytes (75 MiB)
Everything is Ok

real    4m1.607s
user    0m0.000s
sys     0m0.093s
 

总结:在此案例中 7z 在使用合理的压缩级别时,在时间与压缩率都比zip gzip 效果好, 此案例合理的 -mx 参数是 4 ,即: -mx4

你可能感兴趣的:(原创)