How many cmdlet-characters per minute can you type?

So, there are a lot of PowerShell “scripting games” around recently, which is great. But are they really games? 😉

Let’s do something a bit different, let’s measure how fast we can type out cmdlet names!

Tab completion cannot be used, and the input will be compared in a case sensitive way (yes, I know, this is by no means a measure on how good your PowerShell skills are, like, at all. But hey, it’s just a game 🙂 ), the code for the function that can measure this follows (download link):

function Measure-CmdletTypingSpeed {

    <#
    .SYNOPSIS
    Measure the speed and accuracy of typing cmdlet-names.

    .DESCRIPTION
    This function will load a number of random cmdlets from the ones available on
    the local system and measure the speed and accuracy of how they are typed.

    The input and cmdlet names are compared with case sensitivity.

    Yes, this is quite stupid since we all use tab completion "in real life", but
    this is just meant as a game, so try not to get too upset!

    .EXAMPLE
    Measure-CmdletTypingSpeed

    Runs this function.

    .EXAMPLE
    Measure-CmdletTypingSpeed -NumberOfCmdlets 20

    Runs this function. Will load 20 cmdlets that needs to be typed. (Default is 10)

    .PARAMETER NumberOfCmdlets
    Specify how many cmdlets you want to type before the result is posted. Default
    and minimum is 10, maximum 100.
    
    #>

    [cmdletbinding()]
    Param(
        [ValidateRange(10,100)]
        [int] $NumberOfCmdlets = 10)

    # Load a selection of random commands
    $Commands = Get-Command | Where-Object { $_.CommandType -eq 'Cmdlet' } | Get-Random -Count $NumberOfCmdlets

    # Initialize the arrays
    $CorrectlyTypedCommands = @()
    $IncorrectlyTypedCommands = @()

    $StartTime = Get-Date

    # Time to loop through the commands and ask for input
    foreach ($Command in $Commands) {
        $Result = Read-Host -Prompt "Type command: $($Command.Name)"

        if ($Command.Name -ceq $Result) {
            $CorrectlyTypedCommands += $Command.Name
        }
        else {
            $IncorrectlyTypedCommands += $Command.Name
        }
    }

    $EndTime = Get-Date

    # Calculate the time it took
    $TimeSpan = New-TimeSpan -Start $StartTime -End $EndTime

    # Figure out the length (number of characters) of the correctly typed commands
    $LengthOfAllCorrectlyTypedCommands = $CorrectlyTypedCommands | ForEach-Object { $_.ToCharArray() } | Measure-Object | Select-Object -ExpandProperty Count

    # Calculate the results
    $CmdletCharactersPerMinute = [Math]::Round($LengthOfAllCorrectlyTypedCommands/$TimeSpan.TotalMinutes)
    $CmdletsPerMinute = [Math]::Round($CorrectlyTypedCommands.Count/$TimeSpan.TotalMinutes)
    $Accuracy = [Math]::Round($CorrectlyTypedCommands.Count/$Commands.count*100)

        Write-Verbose "Your manage to type $CmdletCharactersPerMinute cmdlet-characters per minute ($CmdletsPerMinute cmdlets/minute). You typed $Accuracy% of the cmdlets correctly!"

        $TypeSpeedResults = New-Object System.Object
        $TypeSpeedResults | Add-Member -Type NoteProperty -Name CmdletCharactersPerMinute -Value $CmdletCharactersPerMinute
        $TypeSpeedResults | Add-Member -Type NoteProperty -Name CmdletsPerMinute -Value $CmdletsPerMinute
        $TypeSpeedResults | Add-Member -Type NoteProperty -Name TotalLengthTypedCorrectly -Value $LengthOfAllCorrectlyTypedCommands
        $TypeSpeedResults | Add-Member -Type NoteProperty -Name Accuracy -Value $Accuracy
        $TypeSpeedResults | Add-Member -Type NoteProperty -Name MisspelledCmdletNames -Value $IncorrectlyTypedCommands

        Write-Output $TypeSpeedResults
}

Download as txt-file.

Screenshot of it in action:
CmdletTypingSpeedDump

Feel free to post suggestions on improving it. And if you want to, share your results in the comments! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.