Skip to content

Instantly share code, notes, and snippets.

@dshafik
Created January 21, 2014 06:40
Show Gist options
  • Save dshafik/8535381 to your computer and use it in GitHub Desktop.
Save dshafik/8535381 to your computer and use it in GitHub Desktop.
<?php
// Just run the script and start typing asap. Hit enter to get a calculation.
$start = microtime(true);
$read = fgets(STDIN);
$end = microtime(true);
echo substr_count($read, " ") . " words in " . ($end - $start) . " seconds" . PHP_EOL;
$interval = $end - $start;
if ($interval < 60) {
$times = 60 / $interval;
} else {
$times = $interval / 60;
}
echo (round(substr_count($read, " ") * $times)) . " words per minute!" . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment