I was talking to Petruchio and others about typing speed the other day and to get a rough estimate of mine, I came up with a little program which I broke down to a one-liner:

perl -e'$x=time;print scalar(split/ /,<>)/(time-$x)*60'

It returns the number of WPM (words per minute) you type. (Tested with Perl 5.6.1)

Suggestions to make this more accurate are very welcome.

Zenon Zabinski | zdog |

Replies are listed 'Best First'.
Re: How fast do I type?
by monkeygirl (Pilgrim) on Sep 10, 2001 at 21:37 UTC

    The standard method for calculating words for the purpose of finding WPM is counting all the characters and dividing by six. Why six? Because the average word is 5 characters long, plus a space.

    I'm really no good at one-liners or golfing, but I quickly modified your code. It obtains the accuracy you're looking for. Tested on ActivePerl Build 629 (Perl v5.6.1).

    #!perl $x=time; $letters=scalar(split//,<>)/6; print $letters/(time-$x)*60;

    If Bill Gates can name a company after his "bedroom" problems, I can have a stupid sig that points it out.
      golfed .... with line breaks and prefix
      perl -e'$x=time;print "WPM:".(scalar(split//,<>)/6)/(time-$x)*60."\n"'
        subtract ."\n" and add e (thanks once again to chipmunk)
        perl -le'$x=time;print "WPM:".(scalar(split//,<>)/6)/(time-$x)*60'
Re: How fast do I type?
by dga (Hermit) on Sep 14, 2001 at 03:02 UTC
    use Time::HiRes qw(time);

    This will give you a floating point time function instead of integer seconds.

    In the current program you will have to type a really long line so that the division errors like 4.9 seconds which will sometimes be 4 seconds and sometimes be 5 seconds which will cause a 25% change in your typing WPM.

    The floating poing time function will fix this up since the steps will be on the order of 0.01 seconds rather than 1 second which will improve the granularity of your estimate 100 times so that a one step change from 4.99 to 5.00 will result in a 0.25% change in the WPM figure.