A shell script to measure your typing speed

Steve Hayman sahayman at iuvax.cs.indiana.edu
Wed Sep 27 14:00:30 AEST 1989


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README type
# Wrapped by sahayman at iuvax on Tue Sep 26 22:59:01 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1131 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XHere is a mindless script to take a stab at measuring your typing
Xspeed.  It runs /usr/games/fortune to come up with a paragraph or so of
Xmeaningful text and displays that; you type it, you hit return twice to
Xindicate that you're done and the script tries to figure out your
Xtyping speed.
X
XI took one typing class in the tenth grade many years ago, so I might
Xhave forgotten the exact rules for measuring typing speed, but I seem
Xto recall that it's something like
X
X	- five characters (including spaces) equals a word
X	- ten words off for every error
X
XIf this is wrong, someone please tell me and I'll fix the script.
X
XI like running this when I'm bored.  It isn't exactly scientific but I
Xfind it fun, especially when I manage to get an absurdly high score on
Xa short fortune.  My best so far is about 120 wpm.
X
XNo Makefile - it's just a shell script.  "chmod +x type" and run it.
XI hope it's portable enough.  It works on Ultrix 3.0 here and I made
Xa token effort to avoid anything non-portable.  Let me know if
Xyou find something that needs to be fixed.
X
XSteve Hayman
Xsahayman at iuvax.cs.indiana.edu
XTue Sep 26 22:55:19 EST 1989
END_OF_FILE
if test 1131 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'type' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'type'\"
else
echo shar: Extracting \"'type'\" \(3838 characters\)
sed "s/^X//" >'type' <<'END_OF_FILE'
X#!/bin/sh
X# typing test
X# usage:
X#	type [-f input-file]
X#	type [fortune options]
X# or just
X#	type
X#
X# Displays the input file (or creates one via "fortune"), asks you to type it,
X# times you and attempts to count errors and compute a words-per-minute score.
X#
X# Assumptions: 5 chars is a word, 10 WPM penalty for error.
X# Whitespace is ignored when computing the score (well, there
X# must be some whitespace between the words) so you can
X# break lines wherever you want.   You can also use the normal line-editing
X# characters.
X#
X# TODO:
X#   Show you exactly what your errors are.
X#   -- maybe use "patch" to apply the diff, but cleverly insert
X#      some highlighting?
X# 
X# Steve Hayman, Indiana U
X# sahayman at iuvax.cs.indiana.edu
X# 88/08/16
X
XPATH=/bin:/usr/bin:/usr/ucb export PATH
XUsage="${0}: Usage: $0 [-f input-file]  or $0 [fortune options]"
X
Xstmp=/tmp/t-s.$$
Xitmp=/tmp/t-i.$$
Xdiff=/tmp/t-d.$$
Xin=/tmp/t-in.$$
Xsource=/tmp/t-source.$$
Xtrap exit 1 2 3 15
Xtrap 'rm -f $in $itmp $stmp $source $diff' 0
X
X# A source of pithy sayings.
Xfortune=/usr/games/fortune
Xif test ! -f $fortune; then
X	echo "${0}: Cannot find $fortune - cannot generate examples."
X	echo "${0}: Try  $0 -f some-input-file"
X	exit 1
Xfi
X
Xchars_per_word=5
Xpenalty_per_error=10
X
X
X# Default is a fortune.
X
Xcase "$1" in
X"-f")	# Input file supplied.
X	shift
X	cat ${1?$Usage}
X	;;
X*)	
X	# Pick up a fortune.  Use the supplied command line options,
X	# so the user can choose short, long, obscene, whatever.
X	
X	$fortune ${1+"$@"}
X	;;
Xesac | sed '/^$/d' >$source		# No blank lines, please.
X
Xclear
Xcat $source
X
Xcat <<EOF
X
X
XType the above, end it with an extra blank line (two carriage returns).
XExact spacing does not matter.  You have five seconds to get ready.
X
XEOF
X
X# the stty's are a lame attempt to disallow typeahead
X
Xstty -echo 
Xfor n in 5 4 3 2 1
Xdo
X	echo -n "$n... "
X	sleep 1
Xdone
X
X# this is supposed to consume typeahead
X
Xstty raw; stty -nl echo cooked
X
X# there are supposed to be a couple of control-G's in this line, which
X# may not have survived the shar/unshar process
X
Xecho "Go!"
Xecho ""
X
X# This awk script is the the best way I could think of to read up to
X# a blank line and quit immediately.  "sed /^$/q" needs to read an extra line,
X# "grep -1 -v '^$'" doesn't work.  Could write some little C thing
X# if we wanted to be really accurate, timewise.
X
X
Xset ` time 2>&1 1>$in </dev/tty awk 'NF == 0 { exit } { print }' `
Xecho "OK ..."
Xseconds=$1
X
Xchars=`wc -c <$in`
Xwords=`echo "scale = 2; $chars / $chars_per_word" | bc`
Xwpm=` echo "scale = 2;  $words * 60 / $seconds " | bc `
X
Xecho "words: $words  seconds: $seconds"
Xecho "Raw WPM: $wpm"
X
X
X# translate the source and input so that they're one word per line,
X# then "diff" them and try to count the results.
X# We ignore all the diff lines that begin with > or < or -, we're
X# only interested in the counts ( 1a2, 3,4c5,6, those things.)
X# We just count up the line numbers - that makes the basic
X# (and imperfect) assumption that there can be no more than one error per word.
X
Xtr -s ' \011' '\012' <$in >$itmp
Xtr -s ' \011' '\012' <$source >$stmp
Xdiff $itmp $stmp >$diff
Xeval ` sed -e '/^[<->]/d' -e 's/[adc]/ & /' <$diff | awk '
X	{
X		nleft = split( $1, left, "," )
X		nright = split ( $3, right, "," )
X		if ( nleft == 1 )
X			left[2] = left[1]
X		if ( nright == 1 )
X			right[2] = right[1]
X
X		if ( $2 == "a" )
X			missing += right[2] - right[1] + 1
X		else if ( $2 == "d" )
X			extra += left[2] - left[1] + 1
X		else if ( $2 == "c" )
X			wrong += right[2] - right[1] + 1
X	}
X	END {	
X		printf "missing=%d\n", missing
X		printf "extra=%d\n", extra
X		printf "wrong=%d\n", wrong
X		printf "total=%d\n", missing + extra + wrong
X	}
X	' `
Xecho "Missing: $missing   Extra: $extra  Wrong: $wrong  Total errors: $total"
X
X
Xawpm=` echo "scale=2; ($words - ($total * $penalty_per_error)) * 60 / $seconds" | bc`
X
X
Xecho "Adjusted WPM: $awpm"
END_OF_FILE
echo shar: 2 control characters may be missing from \"'type'\"
if test 3838 -ne `wc -c <'type'`; then
    echo shar: \"'type'\" unpacked with wrong size!
fi
chmod +x 'type'
# end of 'type'
fi
echo shar: End of shell archive.
exit 0



More information about the Alt.sources mailing list