diff options
author | Jim Meyering <jim@meyering.net> | 1997-12-06 13:42:21 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1997-12-06 13:42:21 +0000 |
commit | 7209272d72110c2ad3d551467d4173a46566c635 (patch) | |
tree | 685d008619bd1d585b5c219849b4b805903ea899 /tests | |
parent | 6ee3c1a91a9228dc7ae196706202b423c96bd4cf (diff) | |
download | coreutils-7209272d72110c2ad3d551467d4173a46566c635.tar.xz |
.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sort-time/Makefile | 33 | ||||
-rw-r--r-- | tests/sort-time/README | 12 | ||||
-rwxr-xr-x | tests/sort-time/rand-gen | 123 |
3 files changed, 168 insertions, 0 deletions
diff --git a/tests/sort-time/Makefile b/tests/sort-time/Makefile new file mode 100644 index 000000000..559c088cd --- /dev/null +++ b/tests/sort-time/Makefile @@ -0,0 +1,33 @@ +N = 1000000 + +dot30 = .............................. +dot31 = $(dot30). + +safe_redirect_prologue = rm -f $@ $@-tmp +safe_redirect = $@-tmp && mv $@-tmp $@ + +time = /p/bin/time --verbose + +all: t30 t31 + +t3%: in-3% + @$(safe_redirect_prologue) + $(time) sort $< > $(safe_redirect) + +rand-digits: rand-gen + @$(safe_redirect_prologue) + ./$< --integer $(N) |tr -d '\012' > $(safe_redirect) + +in-30: rand-digits + @$(safe_redirect_prologue) + perl -pe 's/($(dot30))/$$1\n/g' $< > $(safe_redirect) + +in-31: rand-digits + @$(safe_redirect_prologue) + perl -pe 's/($(dot31))/$$1\n/g' $< > $(safe_redirect) + +clean: + rm -f t30 t31 in-30 in-31 + +realclean: clean + rm -f rand-digits diff --git a/tests/sort-time/README b/tests/sort-time/README new file mode 100644 index 000000000..fcb9d3dca --- /dev/null +++ b/tests/sort-time/README @@ -0,0 +1,12 @@ +determine whether it's worthwhile to add a --line-length=N option to sort. +Add the option and perform this test: + +Test method: +============== +for n in 80 200 400 800 3000; do + sort a file with $n-char lines using the default of N=30 + sort the same file with --line-length=$n + compare run times +done + +do this on at least SunOS, Linux, Solaris diff --git a/tests/sort-time/rand-gen b/tests/sort-time/rand-gen new file mode 100755 index 000000000..f4f110b41 --- /dev/null +++ b/tests/sort-time/rand-gen @@ -0,0 +1,123 @@ +#! /p/bin/perl -w +# Print n pairs of floating point values. +# Each value is in the range [0,1). +# Usage: rand n + +# Use only the basename from the path to this executable in error messages. +($program_name = $0) =~ s|.*/||; + +require 'newgetopt.pl'; +$MAXINT = 0x7fffffff; + +undef $opt_help; +undef $opt_verbose; +undef $opt_integer; +&usage if (&NGetOpt(('seed=i', 'range=s', 'help', 'items-per-line=i', + 'format=s', 'integer', 'verbose')) == 0); + +&usage if (defined ($opt_help)); + +&usage if (scalar (@ARGV) != 1 || $ARGV[0] !~ /^[0-9]+$/); +$n = $ARGV[0]; + +if (!defined ($opt_seed)) + { + $opt_seed = time; + print STDERR "seed= $opt_seed\n" if (defined ($opt_verbose)); + } + +srand ($opt_seed); + +# FIXME: make sure this number is positive. +$opt_items_per_line = 1 if (!defined ($opt_items_per_line)); + +if (defined ($opt_integer)) + { + $opt_format = "%d" if (!defined ($opt_format)); + if (defined ($opt_range)) + { + # FIXME: allow FP endpoints even though --integer specified? + if ($opt_range =~ /^([0-9]+),([0-9]+)$/) + { + $lo = $1; + $hi = $2; + } + else + { + print STDERR ("bad argument `$opt_range' to --range option\n"); + exit 2; + } + } + else + { + $lo = 0; + $hi = $MAXINT; + } + + # Increase by one because we'll have to truncate to get integers. + $hi += 1; + } +else + { + $opt_format = "%.15g" if (!defined ($opt_format)); + if (defined ($opt_range)) + { + if ($opt_range =~ /^(-?[0-9.]+),(-?[0-9.]+)$/) + { + $lo = $1; + $hi = $2; + } + else + { + print STDERR ("bad argument `$opt_range' to --range option\n"); + exit 2; + } + } + else + { + $lo = 0.0; + $hi = 1.0; + } + } + +# FIXME: warn if lo > hi. + +$range = $hi - $lo; + +if ($opt_items_per_line == 1) + { + for ($i=0; $i < $n; $i++) + { + printf $opt_format, $lo + rand($range); + print "\n"; + } + } +else + { + $separator = ' '; + for ($i=0; $i < $n; $i++) + { + for ($j=0; $j < $opt_items_per_line; $j++) + { + printf $opt_format, $lo + rand($range); + print $j == $opt_items_per_line - 1 ? "\n" : $separator; + } + } + } + +exit 0; + +sub usage +{ + print STDERR <<EOF; +Usage: $program_name [OPTIONS] n + --help + --seed=n + --integer + --items-per-line=n + --range=i,j e.g. 3,9 or 1.5,33.9 + --format='%3d' + --verbose (report the seed if it gets default value) +EOF + exit 2; +} |