Fixes 2015/howe scripts, format/typo checks etc.
The try.sh script runs the commands that were in the try section. Having this I discovered some errors in the avgtime.sh script which were fixed, partly by having the cc.1 man page added (as not all systems have cc.1 in /usr/share/man/man1), in this case being gcc.1.gz (unzipped) from Rocky Linux, and maybe other things besides. That script, avgtime.sh, has also been updated to make sure at least two args are used and for ShellCheck though some of the things ShellCheck wants to be done will break the script so those warnings are disabled. The README.md file has been format and typo fixed. The war-and-peace.txt file has been added rather than forcing the script (each time, in fact) to try and download it from Project Gutenberg.
This commit is contained in:
1 parent
3adfc9a06a
commit
ff8d406544
6 files changed
+97186
-50
No files matched your search
+39
-45
@@ -4,6 +4,9 @@
|
|||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
There is an alternate version provided. See [Alternate code](#alternate-code)
|
||||||
|
below.
|
||||||
|
|
||||||
|
|
||||||
## To use:
|
## To use:
|
||||||
|
|
||||||
@@ -17,49 +20,34 @@ make
|
|||||||
### Try:
|
### Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./prog prog.alt.c prog.c
|
./try.sh
|
||||||
|
|
||||||
make test
|
|
||||||
./prog -d ABXYEFCD.tmp ACDBECFD.tmp
|
|
||||||
./prog ABXYEFCD.tmp ACDBECFD.tmp
|
|
||||||
|
|
||||||
rm -f curds.tmp whey.tmp
|
|
||||||
cp /usr/share/man/man1/cc.1 curds.tmp
|
|
||||||
cp /usr/share/man/man1/cc.1 whey.tmp
|
|
||||||
chmod 666 whey.tmp
|
|
||||||
make makeholes
|
|
||||||
./makeholes -n 1000 whey.tmp
|
|
||||||
./prog curds.tmp whey.tmp
|
|
||||||
./avgtime.sh 100 ./prog curds.tmp whey.tmp
|
|
||||||
|
|
||||||
# Assuming curl(1) installed, grab a really HUGE text file.
|
|
||||||
curl -L -o war-and-peace.txt http://www.gutenberg.org/ebooks/2600.txt.utf-8
|
|
||||||
cp war-and-peace.txt nuked.tmp
|
|
||||||
./makeholes -c'~' -n 1000 nuked.tmp
|
|
||||||
./prog war-and-peace.txt nuked.tmp
|
|
||||||
./avgtime.sh 100 ./prog war-and-peace.txt nuked.tmp
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Alternate code:
|
## Alternate code:
|
||||||
|
|
||||||
An alternate version of this entry, `prog.alt.c`, is provided.
|
This alternate version does not use a 64-bit FNV hash. This was the original
|
||||||
This alternate code does not use a 64 bit FNV hash.
|
entry but was changed to be the alt version.
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate build:
|
||||||
|
|
||||||
To compile this alternate version:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make alt
|
make alt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate use:
|
||||||
|
|
||||||
Use `prog.alt` as you would `prog` above.
|
Use `prog.alt` as you would `prog` above.
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
|
|
||||||
This is the best use of the FNV that we have seen in the IOCCC so far!
|
This is the best use of the FNV that we have seen in the IOCCC so far!
|
||||||
The output, when used without -d, is compatible with POSIX diff and
|
The output, when used without `-d`, is compatible with POSIX `diff(1)` and
|
||||||
is suitable for use with patch.
|
is suitable for use with `patch(1)`.
|
||||||
|
|
||||||
We welcome back Canada to the list of nations from where winning
|
We welcome back Canada to the list of nations from where winning
|
||||||
entries have been submitted.
|
entries have been submitted.
|
||||||
@@ -70,58 +58,64 @@ during a South Park P.T.A. Meeting?
|
|||||||
|
|
||||||
"We must stop dirty (C) language from getting to our children's ears!"
|
"We must stop dirty (C) language from getting to our children's ears!"
|
||||||
|
|
||||||
[Blame Canada](https://www.youtube.com/watch?v=bOR38552MJA):
|
[Blame Canada](https://www.youtube.com/watch?v=bOR38552MJA)
|
||||||
|
|
||||||
Or should we teach our youth to understand the intricacies of this code?
|
Or should we teach our youth to understand the intricacies of this code?
|
||||||
Ying Tong Iddle I Po! We suggest you read the source for yourself, which
|
Ying Tong Iddle I Po! We suggest you read the source for yourself, which
|
||||||
might be easier than the academic papers it was inspired by.
|
might be easier than the academic papers it was inspired by.
|
||||||
|
|
||||||
NOTE: Unlike the original entry source, prog.alt.c, prog.c uses a
|
NOTE: Unlike the original entry source, [prog.alt.c](prog.alt.c),
|
||||||
|
[prog.c](prog.c) uses a
|
||||||
64 bit FNV hash and fixes a function call warning.
|
64 bit FNV hash and fixes a function call warning.
|
||||||
|
|
||||||
|
|
||||||
## Author's remarks:
|
## Author's remarks:
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* "An O(NP) Sequence Comparison Algorithm" by Wu, Manber, Myers, Miller.
|
* "An O(NP) Sequence Comparison Algorithm" by Wu, Manber, Myers, Miller.
|
||||||
|
|
||||||
* Output compatible with patch(1).
|
* Output compatible with `patch(1)`.
|
||||||
|
|
||||||
* Strokes one of the judge's ego (I couldn't email chocolate or curry).
|
* Strokes one of the judge's ego (I couldn't email chocolate or curry).
|
||||||
|
|
||||||
|
|
||||||
### Description
|
### Description
|
||||||
|
|
||||||
This is a functioning micro diff tool using an [O(NP) algorithm][Wu+89],
|
This is a functioning micro `diff(1)` tool using an [O(NP) algorithm][Wu+89],
|
||||||
compared to the older [O(ND) difference algorithm][Mye86] used by some versions
|
compared to the older [O(ND) difference algorithm][Mye86] used by some versions
|
||||||
of diff. Its output is based on the default diff(1) output described by POSIX
|
of `diff(1)`. Its output is based on the default `diff(1)` output described by POSIX
|
||||||
and [The Open Group Base Specifications][SUSV7]. The output is suitable for use
|
and [the Open Group Base Specifications][SUSV7]. The output is suitable for use
|
||||||
with patch(1).
|
with `patch(1)`.
|
||||||
|
|
||||||
|
The `-d` option simply writes the edit distance between `file1` and `file2`.
|
||||||
|
|
||||||
The -d option simply writes the edit distance between file1 and file2.
|
|
||||||
|
|
||||||
### Observations
|
### Observations
|
||||||
|
|
||||||
The FNV1a hash is a little slow compared to the trivial hash GNU Diff uses. I
|
The FNV1a hash is a little slow compared to the trivial hash [GNU
|
||||||
downloaded a plain text copy of "War And Peace" from Project Gutenberg, used
|
diff](https://www.gnu.org/software/diffutils/) uses. I downloaded a plain text
|
||||||
``makeholes.c`` to make 1000 random changes, then profiled and timed the program
|
copy of "War And Peace" from [Project Gutenberg](https://www.gutenberg.org),
|
||||||
verses GNU Diff. The bottleneck appears to be in the file I/O and line hashing
|
used [makeholes.c](makeholes.c) to make 1000 random changes, then profiled and
|
||||||
with an average +0.05s slower. Using a huge file like "War And Peace" for
|
timed the program verses GNU `diff(1)`. The bottleneck appears to be in the
|
||||||
testing offsets the diff(1) optimised file I/O.
|
file I/O and line hashing with an average +0.05s slower. Using a huge file like
|
||||||
|
"War And Peace" for testing offsets the `diff(1)` optimised file I/O.
|
||||||
|
|
||||||
There is no hash collision checking, partly because FNV1a appears to generate
|
There is no hash collision checking, partly because FNV1a appears to generate
|
||||||
very [few collisions][HshCmp] and an assumption that localised collisions within
|
very [few collisions][HshCmp] and an assumption that localised collisions within
|
||||||
a region of edits are highly unlikely.
|
a region of edits are highly unlikely.
|
||||||
|
|
||||||
|
|
||||||
### Support Files
|
### Support Files
|
||||||
|
|
||||||
* ``prog-test.sh``\
|
* [prog-test.sh](prog-test.sh)
|
||||||
Basic test program verifies known test edit distances and patch support.
|
Basic test program verifies known test edit distances and `patch(1)` support.
|
||||||
|
|
||||||
* ``avgtime.sh``
|
* [avgtime.sh](avgtime.sh)
|
||||||
|
|
||||||
* ``makeholes.c``\
|
* [makeholes.c](makeholes.c)
|
||||||
Random edits (holes) made to a file in-place.
|
Random edits (holes) made to a file in-place.
|
||||||
|
|
||||||
### References
|
### References
|
||||||
|
|
||||||
|
|||||||
+24
-5
@@ -1,6 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ "$#" -lt 2 ]]; then
|
||||||
|
echo "usage: $0 <count> <command>" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
COUNT=$1; shift
|
COUNT=$1; shift
|
||||||
|
# ^--^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
|
||||||
|
# shellcheck disable=SC2124
|
||||||
CMD="$@"
|
CMD="$@"
|
||||||
|
|
||||||
N=0
|
N=0
|
||||||
@@ -8,15 +15,27 @@ SYS=0
|
|||||||
USER=0
|
USER=0
|
||||||
REAL=0
|
REAL=0
|
||||||
|
|
||||||
while [ $N -lt $COUNT ]; do
|
while [[ $N -lt $COUNT ]]; do
|
||||||
|
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
|
||||||
|
# 'fixing' this will break the script so we disable it:
|
||||||
|
# shellcheck disable=SC2086
|
||||||
TIME=$( { /usr/bin/time -l $CMD >/dev/null; } 2>&1 | head -n 1 )
|
TIME=$( { /usr/bin/time -l $CMD >/dev/null; } 2>&1 | head -n 1 )
|
||||||
|
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
|
||||||
|
# 'fixing' this will break the script so we disable it:
|
||||||
|
# shellcheck disable=SC2086
|
||||||
REAL="$REAL + $(echo $TIME | cut -d' ' -f1)"
|
REAL="$REAL + $(echo $TIME | cut -d' ' -f1)"
|
||||||
|
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
|
||||||
|
# 'fixing' this will break the script so we disable it:
|
||||||
|
# shellcheck disable=SC2086
|
||||||
USER="$USER + $(echo $TIME | cut -d' ' -f3)"
|
USER="$USER + $(echo $TIME | cut -d' ' -f3)"
|
||||||
|
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
|
||||||
|
# 'fixing' this will break the script so we disable it:
|
||||||
|
# shellcheck disable=SC2086
|
||||||
SYS="$SYS + $(echo $TIME | cut -d' ' -f5)"
|
SYS="$SYS + $(echo $TIME | cut -d' ' -f5)"
|
||||||
(( N = $N + 1 ))
|
((N++))
|
||||||
done
|
done
|
||||||
|
|
||||||
printf 'avg-real\t%.3f\n' $(echo "scale=3; ( $REAL ) / $COUNT" | bc)
|
printf 'avg-real\t%.3f\n' "$(echo "scale=3; ( $REAL ) / $COUNT" | bc)"
|
||||||
printf 'avg-user\t%.3f\n' $(echo "scale=3; ( $USER ) / $COUNT" | bc)
|
printf 'avg-user\t%.3f\n' "$(echo "scale=3; ( $USER ) / $COUNT" | bc)"
|
||||||
printf 'avg-sys\t%.3f\n' $(echo "scale=3; ( $SYS ) / $COUNT" | bc)
|
printf 'avg-sys\t%.3f\n' "$(echo "scale=3; ( $SYS ) / $COUNT" | bc)"
|
||||||
|
|
||||||
+31041
File diff suppressed because it is too large.
Load diff
Executable
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.sh - demonstrate IOCCC winner 2015/howe
|
||||||
|
#
|
||||||
|
|
||||||
|
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
|
||||||
|
# this way allows us to have the user specify a different compiler in an easy
|
||||||
|
# way.
|
||||||
|
if [[ -z "$CC" ]]; then
|
||||||
|
CC="cc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
make CC="$CC" all >/dev/null || exit 1
|
||||||
|
|
||||||
|
# clear screen after compilation so that only the entry is shown
|
||||||
|
clear
|
||||||
|
|
||||||
|
|
||||||
|
./prog prog.alt.c prog.c
|
||||||
|
|
||||||
|
make test
|
||||||
|
./prog -d ABXYEFCD.tmp ACDBECFD.tmp
|
||||||
|
./prog ABXYEFCD.tmp ACDBECFD.tmp
|
||||||
|
|
||||||
|
rm -f curds.tmp whey.tmp
|
||||||
|
cp -f cc.1 curds.tmp
|
||||||
|
cp -f cc.1 whey.tmp
|
||||||
|
chmod 666 whey.tmp
|
||||||
|
make makeholes
|
||||||
|
./makeholes -n 1000 whey.tmp
|
||||||
|
./prog curds.tmp whey.tmp
|
||||||
|
./avgtime.sh 100 ./prog curds.tmp whey.tmp
|
||||||
|
|
||||||
|
cp -f war-and-peace.txt nuked.tmp
|
||||||
|
./makeholes -c'~' -n 1000 nuked.tmp
|
||||||
|
./prog war-and-peace.txt nuked.tmp
|
||||||
|
./avgtime.sh 100 ./prog war-and-peace.txt nuked.tmp
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -3803,6 +3803,15 @@ simply typing `make back_to` or `make mullender`.
|
|||||||
(Linux doesn't seem to but macOS does).
|
(Linux doesn't seem to but macOS does).
|
||||||
|
|
||||||
|
|
||||||
|
## [2015/howe](2015/howe/prog.c) ([README.md](2015/howe/README.md))
|
||||||
|
|
||||||
|
[Cody](#cody) added the [try.sh](2015/howe/try.sh) script, downloaded the War
|
||||||
|
and Peace text file, fixed the [avgtime.sh](2015/howe/avgtime.sh) script (it
|
||||||
|
resulted in standard input errors in piping to `bc(1)`) and added the
|
||||||
|
[cc.1](2015/howe/cc.1) man page as not all systems have it (in fact it's
|
||||||
|
`gcc(1)` from Rocky Linux).
|
||||||
|
|
||||||
|
|
||||||
## [2015/mills1](2015/mills1/prog.c) ([README.md](2015/mills1/README.md))
|
## [2015/mills1](2015/mills1/prog.c) ([README.md](2015/mills1/README.md))
|
||||||
|
|
||||||
[Cody](#cody) added the [try.sh](2015/mills1/try.sh) script which changes the
|
[Cody](#cody) added the [try.sh](2015/mills1/try.sh) script which changes the
|
||||||
|
|||||||
Reference in new issue
Block a user