go>> wc>> 返回
项目作者: avegner

项目描述 :
wc utility written in Go
高级语言: Go
项目地址: git://github.com/avegner/wc.git
创建时间: 2020-03-05T13:26:10Z
项目社区:https://github.com/avegner/wc

开源协议:MIT License

下载


wc

Well-known wc utility written in Go. Simplified version.

Installation

  1. GOFLAGS='-ldflags=-s -trimpath' go get github.com/avegner/wc

Usage

  1. Usage: wc FILE...
  2. Print newline, word, byte and character counts for each FILE, and a total line if
  3. more than one FILE is specified. A word is a non-zero-length sequence of
  4. characters delimited by white space. Unicode BOM isn't considered a character.
  5. Only ASCII and UTF-8 encodings are supported. Invalid characters are ignored.

Benchmarking

  • install time utility:
    1. sudo apt update
    2. sudo apt install -y time
  • run original wc:
    1. $(which time) -v wc -mclw <file>...
  • run go wc:
    1. $(which time) -v $(go env GOPATH)/bin/wc <file>...
  • compare mem and cpu usage stats

UPX for Go bins

Static Go binaries are significantly larger than C ones. Use UPX to reduce binary size:

  1. sudo apt update
  2. sudo apt install -y upx
  3. upx -9 -o $(go env GOPATH)/bin/wc.upx $(go env GOPATH)/bin/wc

Output Format

  1. <lines> <words> <chars> <bytes> <file-path>
  2. ...

Stats

Wall clock

Test wc -mclw Go wc Go wc.upx
1 x 320.4 MiB UTF-8 file 2.14 s 3.69 s 3.77 s
10 x 320.4 MiB UTF-8 files 21.51 s 20.59 s 20.65 s

Maximum RSS

Test wc -mclw Go wc Go wc.upx
1 x 320.4 MiB UTF-8 file 2220 KiB 2132 KiB 2168 KiB
10 x 320.4 MiB UTF-8 files 2228 KiB 2384 KiB 2424 KiB