Skip to content

kegliz/gengo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Benchmarking the Overhead of Go Generics

This repo includes a basic benchmark analysis of the performance overhead associated with using Go generics. It compares a generic-based stack implementation with a non-generic version.

The comparison covers

  • int values and
  • a simple struct.

How to Run the Benchmark

go run main.go

Implementation

The generic stack implementation is based on the following type definition:

type Stack[T any] struct {
  data []T
}

This is located in the package github.com/kegliz/gengo/genstack.

The non-generic int stack implementation is based on the following type definition:

type Stack struct {
  data []int
}

This is located in the package github.com/kegliz/gengo/intstack.

The non-generic struct stack implementation is based on the following type definition:

type Item struct {
		Name string
		Age  int
	}

type Stack struct {
  data []Item
}

This is located in the package github.com/kegliz/gengo/structstack.

The benchmarking code is located in the main package. In order to to avoid the compiler optimizing out the operations, the results are stored in a variable that is written to /dev/null at the end of the benchmark.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages