uutils/coreutils — pull request #272 by kwantam (2014-06-19 01:02:30+00:00)
Title: implementation of fmt

I've got an initial implementation of fmt completed. The options are sort of a combination of GNU and BSD, with a couple extra minor ones that I added because it seemed sensible and relatively straightforward.

Note: for now, this version does not use Knuth-Plass, but everything else is in place using "greedy" breaking. I've got a working Knuth-Plass implementation in Haskell that I'm going to port over.

All options (should) work, and performance is nearly on par with GNU fmt:

$ ls -lah playground/long
-rw-r--r-- 1 kwantam kwantam 42M Jun 18 20:51 playground/long
$ perf stat -r 20 fmt playground/long >/dev/null

Performance counter stats for './fmt playground/long' (20 runs):

1077.217547 task-clock (msec) # 0.999 CPUs utilized ( +- 0.34% )
12 context-switches # 0.011 K/sec ( +- 12.48% )
3 cpu-migrations # 0.003 K/sec ( +- 27.58% )
184 page-faults # 0.171 K/sec ( +- 0.04% )
3,485,343,206 cycles # 3.236 GHz ( +- 0.06% )
833,519,491 stalled-cycles-frontend # 23.91% frontend cycles idle ( +- 0.20% )
stalled-cycles-backend
7,521,678,405 instructions # 2.16 insns per cycle
# 0.11 stalled cycles per insn ( +- 0.00% )
1,439,929,997 branches # 1336.712 M/sec ( +- 0.00% )
40,051,616 branch-misses # 2.78% of all branches ( +- 0.01% )

1.078562530 seconds time elapsed ( +- 0.34% )

$ perf stat -r 20 ./fmt playground/long >/dev/null

Performance counter stats for './fmt playground/long' (20 runs):

1267.654011 task-clock (msec) # 0.999 CPUs utilized ( +- 0.23% )
10 context-switches # 0.008 K/sec ( +- 7.02% )
2 cpu-migrations # 0.002 K/sec ( +- 43.83% )
101,079 page-faults # 0.080 M/sec ( +- 0.00% )
4,125,868,082 cycles # 3.255 GHz ( +- 0.03% )
896,450,011 stalled-cycles-frontend # 21.73% frontend cycles idle ( +- 0.05% )
stalled-cycles-backend
9,669,115,061 instructions # 2.34 insns per cycle
# 0.09 stalled cycles per insn ( +- 0.00% )
2,302,891,543 branches # 1816.656 M/sec ( +- 0.00% )
19,958,464 branch-misses # 0.87% of all branches ( +- 0.00% )

1.268852889 seconds time elapsed ( +- 0.23% )