Golang

 

 

Introduction

A typing speed test is a simple yet effective way to measure how fast you can type text on your keyboard. It is widely used to gauge typing proficiency, whether for professional purposes or casual practice. This project demonstrates how to create a basic typing speed test application using the Go programming language.

Objective

The objective of this program is to create an application that prompts the user to type a given passage as fast as they can. The program will then calculate and display the typing speed in words per minute (WPM) along with the accuracy. It will also display the time taken for completion and highlight any mistakes made by the user.

Code Implementation


package main

import (
“fmt”
“strings”
“time”
)

func main() {
// Define the test text
testText := “The quick brown fox jumps over the lazy dog.”

// Display the test text to the user
fmt.Println(“Typing Speed Test”)
fmt.Println(“——————“)
fmt.Println(“Type the following text:”)
fmt.Println(testText)
fmt.Println()

// Record the start time
startTime := time.Now()

// Get user input
fmt.Print(“Start typing: “)
var userInput string
fmt.Scanln(&userInput)

// Calculate the time taken to complete the typing
endTime := time.Now()
timeTaken := endTime.Sub(startTime)

// Check for any errors in the input
errors := 0
for i := 0; i < len(testText); i++ { if i >= len(userInput) || testText[i] != userInput[i] {
errors++
}
}

// Calculate words per minute
wordsTyped := len(strings.Fields(userInput))
minutes := timeTaken.Seconds() / 60

// Calculate typing speed and accuracy
wpm := float64(wordsTyped) / minutes
accuracy := (float64(len(testText)-errors) / float64(len(testText))) * 100

// Display results
fmt.Printf(“\nTime taken: %.2f seconds\n”, timeTaken.Seconds())
fmt.Printf(“Typing speed: %.2f WPM\n”, wpm)
fmt.Printf(“Accuracy: %.2f%%\n”, accuracy)
}

Explanation of Program Structure

The program is structured in a simple, linear manner. The steps of the program are as follows:

  • Define the test text: A fixed sentence is provided for the user to type.
  • Display instructions: The program prompts the user to type the text.
  • Record the start time: The program starts measuring the time as soon as the user begins typing.
  • Get user input: The program accepts the user’s typed input.
  • Calculate time taken: The program calculates how long the user took to type the passage.
  • Count errors: The program compares the user’s input with the original text and counts errors.
  • Calculate typing speed and accuracy: Words per minute (WPM) and accuracy are calculated based on the user’s performance.
  • Display results: Finally, the program outputs the time taken, typing speed, and accuracy to the user.

How to Run the Program

To run the program on your local machine, follow these steps:

  • Ensure that you have the Go programming language installed. You can download it from here.
  • Create a new file called typing_speed_test.go on your local system and paste the provided code into it.
  • Open your terminal or command prompt and navigate to the directory containing the file.
  • Run the program by typing go run typing_speed_test.go in the terminal.
  • Follow the instructions provided by the program and start typing the passage as fast and accurately as possible.
  • The program will then display your typing speed and accuracy.
© 2025 Learn Programming. All Rights Reserved.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

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

error

Enjoy this blog? Please spread the word :)