Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Concurrency, Testing & Benchmarking Lab

A practical Go repository built while learning and revising core backend development concepts related to concurrency, synchronization, testing, and performance benchmarking.

The goal of this repository is to understand how Go handles concurrent execution and how these concepts can be tested and measured using Go's built-in tooling.

Topics Covered

Goroutines

Examples covering:

  • Creating goroutines
  • Passing parameters to goroutines
  • Returning values using channels
  • Running tasks concurrently
  • Using sync.WaitGroup
  • Concurrent user/data fetching examples

Channels

Examples covering:

  • Creating channels
  • Sending and receiving values
  • Unbuffered channels
  • Buffered channels
  • Closing channels
  • Channel communication
  • Using channels to return values
  • Using channels for synchronization
  • select statement
  • select with timeout

Synchronization

Examples covering:

  • Race conditions
  • sync.Mutex
  • sync.RWMutex
  • Atomic operations
  • Protecting shared data
  • Synchronizing concurrent operations

Testing

Examples using Go's built-in testing package.

Covered concepts:

  • Unit testing
  • go test
  • Verbose testing with go test -v
  • Expected vs actual results
  • Table-driven tests
  • Subtests using t.Run()
  • Race detection with go test -race

Example:

go test ./...

Verbose output:

go test -v ./...

Race detection:

go test -race ./...

Benchmarking

Examples demonstrating Go's built-in benchmarking tools.

Covered concepts:

  • Creating benchmark functions
  • testing.B
  • b.N
  • Comparing implementations
  • Reading benchmark results
  • Measuring memory allocations

Run benchmarks:

go test -bench=. ./...

Run benchmarks with memory statistics:

go test -bench=. -benchmem ./...

Benchmark output can include:

  • ns/op — nanoseconds per operation
  • B/op — bytes allocated per operation
  • allocs/op — allocations per operation

Example Benchmark

This repository contains a simple comparison between two ways of iterating through and summing a slice:

func Sum(numbers []int) int {
    total := 0

    for _, number := range numbers {
        total += number
    }

    return total
}

and an index-based implementation.

The implementations are compared using Go benchmarks.

Running the Repository

Clone the repository:

git clone https://github.com/muhammadasad70/go-concurrency-testing-lab.git

Move into the project:

cd go-concurrency-testing-lab

Download or verify module dependencies:

go mod tidy

Run all tests:

go test ./...

Run benchmarks:

go test -bench=. ./...

Tech

  • Go
  • Goroutines
  • Channels
  • Mutex
  • RWMutex
  • Atomic Operations
  • Go Testing
  • Race Detector
  • Go Benchmarking

Purpose

This repository is part of my backend engineering learning journey, with a focus on understanding Go concepts through implementation rather than theory alone.

It will continue to evolve as I learn and implement more concurrency, testing, and performance concepts.

About

Hands-on Go implementations covering goroutines, channels, synchronization, testing, race detection, and benchmarking.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages