summaryrefslogtreecommitdiffstats
path: root/Demo/comparisons
diff options
context:
space:
mode:
Diffstat (limited to 'Demo/comparisons')
-rw-r--r--Demo/comparisons/README60
-rwxr-xr-xDemo/comparisons/patterns4
-rwxr-xr-xDemo/comparisons/regextest.py47
-rwxr-xr-xDemo/comparisons/sortingtest.py45
-rwxr-xr-xDemo/comparisons/systemtest.py74
5 files changed, 0 insertions, 230 deletions
diff --git a/Demo/comparisons/README b/Demo/comparisons/README
deleted file mode 100644
index 111667c..0000000
--- a/Demo/comparisons/README
+++ /dev/null
@@ -1,60 +0,0 @@
-Subject: Re: What language would you use?
-From: Tom Christiansen <tchrist@mox.perl.com>
-Date: 6 Nov 1994 15:14:51 GMT
-Newsgroups: comp.lang.python,comp.lang.tcl,comp.lang.scheme,comp.lang.misc,comp.lang.perl
-Message-Id: <39irtb$3t4@csnews.cs.Colorado.EDU>
-References: <39b7ha$j9v@zeno.nscf.org> <39hhjp$lgn@csnews.cs.Colorado.EDU> <39hvsu$dus@mathserv.mps.ohio-state.edu>
-
-[...]
-If you're really into benchmarks, I'd love it if someone were to code up
-the following problems in tcl, python, and scheme (and whatever else you'd
-like). Separate versions (one optimized for speed, one for beauty :-) are
-ok. Post your code so we can time it on our own systems.
-
-0) Factorial Test (numerics and function calls)
-
- (we did this already)
-
-1) Regular Expressions Test
-
- Read a file of (extended per egrep) regular expressions (one per line),
- and apply those to all files whose names are listed on the command line.
- Basically, an 'egrep -f' simulator. Test it with 20 "vt100" patterns
- against a five /etc/termcap files. Tests using more elaborate patters
- would also be interesting. Your code should not break if given hundreds
- of regular expressions or binary files to scan.
-
-2) Sorting Test
-
- Sort an input file that consists of lines like this
-
- var1=23 other=14 ditto=23 fred=2
-
- such that each output line is sorted WRT to the number. Order
- of output lines does not change. Resolve collisions using the
- variable name. e.g.
-
- fred=2 other=14 ditto=23 var1=23
-
- Lines may be up to several kilobytes in length and contain
- zillions of variables.
-
-3) System Test
-
- Given a list of directories, report any bogus symbolic links contained
- anywhere in those subtrees. A bogus symbolic link is one that cannot
- be resolved because it points to a nonexistent or otherwise
- unresolvable file. Do *not* use an external find executable.
- Directories may be very very deep. Print a warning immediately if the
- system you're running on doesn't support symbolic links.
-
-
-I'll post perl solutions if people post the others.
-
-
---tom
---
-Tom Christiansen Perl Consultant, Gamer, Hiker tchrist@mox.perl.com
-
- "But Billy! A *small* allowance prepares you for a lifetime of small
- salaries and for your Social Security payments." --Family Circus
diff --git a/Demo/comparisons/patterns b/Demo/comparisons/patterns
deleted file mode 100755
index f4da846..0000000
--- a/Demo/comparisons/patterns
+++ /dev/null
@@ -1,4 +0,0 @@
-^def
-^class
-^import
-^from
diff --git a/Demo/comparisons/regextest.py b/Demo/comparisons/regextest.py
deleted file mode 100755
index 547ee0d..0000000
--- a/Demo/comparisons/regextest.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#! /usr/bin/env python3
-
-# 1) Regular Expressions Test
-#
-# Read a file of (extended per egrep) regular expressions (one per line),
-# and apply those to all files whose names are listed on the command line.
-# Basically, an 'egrep -f' simulator. Test it with 20 "vt100" patterns
-# against a five /etc/termcap files. Tests using more elaborate patters
-# would also be interesting. Your code should not break if given hundreds
-# of regular expressions or binary files to scan.
-
-# This implementation:
-# - combines all patterns into a single one using ( ... | ... | ... )
-# - reads patterns from stdin, scans files given as command line arguments
-# - produces output in the format <file>:<lineno>:<line>
-# - is only about 2.5 times as slow as egrep (though I couldn't run
-# Tom's test -- this system, a vanilla SGI, only has /etc/terminfo)
-
-import string
-import sys
-import re
-
-def main():
- pats = list(map(chomp, sys.stdin.readlines()))
- bigpat = '(' + '|'.join(pats) + ')'
- prog = re.compile(bigpat)
-
- for file in sys.argv[1:]:
- try:
- fp = open(file, 'r')
- except IOError as msg:
- print("%s: %s" % (file, msg))
- continue
- lineno = 0
- while 1:
- line = fp.readline()
- if not line:
- break
- lineno = lineno + 1
- if prog.search(line):
- print("%s:%s:%s" % (file, lineno, line), end=' ')
-
-def chomp(s):
- return s.rstrip('\n')
-
-if __name__ == '__main__':
- main()
diff --git a/Demo/comparisons/sortingtest.py b/Demo/comparisons/sortingtest.py
deleted file mode 100755
index e826e81..0000000
--- a/Demo/comparisons/sortingtest.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#! /usr/bin/env python3
-
-# 2) Sorting Test
-#
-# Sort an input file that consists of lines like this
-#
-# var1=23 other=14 ditto=23 fred=2
-#
-# such that each output line is sorted WRT to the number. Order
-# of output lines does not change. Resolve collisions using the
-# variable name. e.g.
-#
-# fred=2 other=14 ditto=23 var1=23
-#
-# Lines may be up to several kilobytes in length and contain
-# zillions of variables.
-
-# This implementation:
-# - Reads stdin, writes stdout
-# - Uses any amount of whitespace to separate fields
-# - Allows signed numbers
-# - Treats illegally formatted fields as field=0
-# - Outputs the sorted fields with exactly one space between them
-# - Handles blank input lines correctly
-
-import re
-import sys
-
-def main():
- prog = re.compile('^(.*)=([-+]?[0-9]+)')
- def makekey(item, prog=prog):
- match = prog.match(item)
- if match:
- var, num = match.groups()
- return int(num), var
- else:
- # Bad input -- pretend it's a var with value 0
- return 0, item
- for line in sys.stdin:
- items = sorted(makekey(item) for item in line.split())
- for num, var in items:
- print("%s=%s" % (var, num), end=' ')
- print()
-
-main()
diff --git a/Demo/comparisons/systemtest.py b/Demo/comparisons/systemtest.py
deleted file mode 100755
index 8276333..0000000
--- a/Demo/comparisons/systemtest.py
+++ /dev/null
@@ -1,74 +0,0 @@
-#! /usr/bin/env python3
-
-# 3) System Test
-#
-# Given a list of directories, report any bogus symbolic links contained
-# anywhere in those subtrees. A bogus symbolic link is one that cannot
-# be resolved because it points to a nonexistent or otherwise
-# unresolvable file. Do *not* use an external find executable.
-# Directories may be very very deep. Print a warning immediately if the
-# system you're running on doesn't support symbolic links.
-
-# This implementation:
-# - takes one optional argument, using the current directory as default
-# - uses chdir to increase performance
-# - sorts the names per directory
-# - prints output lines of the form "path1 -> path2" as it goes
-# - prints error messages about directories it can't list or chdir into
-
-import os
-import sys
-from stat import *
-
-def main():
- try:
- # Note: can't test for presence of lstat -- it's always there
- dummy = os.readlink
- except AttributeError:
- print("This system doesn't have symbolic links")
- sys.exit(0)
- if sys.argv[1:]:
- prefix = sys.argv[1]
- else:
- prefix = ''
- if prefix:
- os.chdir(prefix)
- if prefix[-1:] != '/': prefix = prefix + '/'
- reportboguslinks(prefix)
- else:
- reportboguslinks('')
-
-def reportboguslinks(prefix):
- try:
- names = os.listdir('.')
- except os.error as msg:
- print("%s%s: can't list: %s" % (prefix, '.', msg))
- return
- names.sort()
- for name in names:
- if name == os.curdir or name == os.pardir:
- continue
- try:
- mode = os.lstat(name)[ST_MODE]
- except os.error:
- print("%s%s: can't stat: %s" % (prefix, name, msg))
- continue
- if S_ISLNK(mode):
- try:
- os.stat(name)
- except os.error:
- print("%s%s -> %s" % \
- (prefix, name, os.readlink(name)))
- elif S_ISDIR(mode):
- try:
- os.chdir(name)
- except os.error as msg:
- print("%s%s: can't chdir: %s" % \
- (prefix, name, msg))
- continue
- try:
- reportboguslinks(prefix + name + '/')
- finally:
- os.chdir('..')
-
-main()