CEG's Linux User Group

  • Increase font size
  • Default font size
  • Decrease font size
Home General HOW FAST CAN YOU TYPE????!!!!

HOW FAST CAN YOU TYPE????!!!!

E-mail Print
User Rating: / 8
PoorBest 
If you spend most of your time typing on your keyboard getting up to speed and practicing to become a better and faster typist is well worth the time and effort. And measuring something is the first step to improve it.
There are tons of applications which test your typing abilities and help you improve it, but wouldn’t it be nice to have a basic idea about your typing performance using nothing but good old Bash? After all, this is about DIY (Do It Yourself) approach and having fun!!!!
Measuring the typing speed means basically measuring how many words you typed in a given amount of time. One of the most popular units used is wpm (words per minute). Maybe not very accurate and scientific, but we’re aiming for a ballpark figure here so some approximate measure will be fine for our purpose. Based on this information we can write the formula as:

typing_speed_in_wpm = num_words / ( (end_time - start_time) / 60 )
Now that we have our theoretical framework set up, it is time to build the practical computational part of the project. Before diving into code, let’s break down the above formula into pieces and see which GNU/Linux utilities can help us achieve various tasks:

• date : This is our well-known utility and if you use it with the %s format specifier it returns the “seconds since 1970-01-01 00:00:00 UTC”. So if you run date +%s once at the beginning of your typing session and once at the end of it, you’ll have the end_time and start_time.

• wc: This is yet another well-known utility that can give you the number of words in a file if invoked with -w option. And remember, in GNU/Linux almost everything is a file, including your input from the keyboard.

• cat: Officially it concatenates files and print them on the standard output. Practically it can grab your input from the keyboard and via a pipe send that to the wc. In other words all we need to do to count the number of words we just typed is to issue the following command: cat | wc -w

• bc: Officially it is an arbitrary precision calculator language. Practically it is a very handy utility if you want to do calculations within the command line.

$echo 1 / 2 | bc
0

That’s not what you’d expect from a computer. Why doesn’t it return the correct answer, that is 0.5? scale defines how some operations use digits after the decimal point. The default value of scale is 0.” Apparently it is not a very sensible default for our division operations which we’ll use later. The solution then is to tell bc what scale to use before doing the operation, e.g.:

$ echo “scale=2; 1 / 2” | bc
0.50

Now it is time to glue them together using our favorite application development environment,

Bash:
#!/bin/sh
prompt="Start typing a piece of text Press Ctrl-d twice to finish."
echo "\n$prompt \n"
start_time=`date +%s`
words=`cat|wc -w`
end_time=`date +%s`
speed=`echo "scale=2; $words / ( ( $end_time - $start_time ) / 60)" | bc`
echo "\n\nYou have a typing speed of $speed words per minute."

If you save the above shell script as speed.sh and make it e xecutable, you are ready to measure your typing speed. Happy typing :) :)
Last Updated on Tuesday, 12 July 2011 22:41  
Please register or login to add your comments to this article.