Code Monkey home page Code Monkey logo

bpgg's Introduction

Benchmarking the performance of Go generics

This repository benchmarks the performance of Go generics.

Benchmarks

Boxing

This benchmark demonstrates how Go generics eliminates the need for the boxing that occurs with the use of interface{} by implementing a simple vector:

$ go test -bench . -benchmem -count 5 -memprofile ./boxing/memprofile.out -v ./boxing/
goos: darwin
goarch: arm64
pkg: bpgg/boxing
BenchmarkInterfaceVector
BenchmarkInterfaceVector-8   	18319783	        62.84 ns/op	      96 B/op	       1 allocs/op
BenchmarkInterfaceVector-8   	26550849	        65.01 ns/op	     103 B/op	       1 allocs/op
BenchmarkInterfaceVector-8   	24785962	        58.35 ns/op	      89 B/op	       1 allocs/op
BenchmarkInterfaceVector-8   	23335028	        60.32 ns/op	      94 B/op	       1 allocs/op
BenchmarkInterfaceVector-8   	24852051	        49.56 ns/op	      89 B/op	       1 allocs/op
BenchmarkGenericVector
BenchmarkGenericVector-8     	74692666	        16.99 ns/op	      49 B/op	       0 allocs/op
BenchmarkGenericVector-8     	75874735	        15.93 ns/op	      48 B/op	       0 allocs/op
BenchmarkGenericVector-8     	74793732	        15.93 ns/op	      49 B/op	       0 allocs/op
BenchmarkGenericVector-8     	75018556	        15.83 ns/op	      48 B/op	       0 allocs/op
BenchmarkGenericVector-8     	73958611	        15.85 ns/op	      49 B/op	       0 allocs/op
PASS
ok  	bpgg/boxing	13.495s

A few, key takeaways:

  • On average the implementation of GVector[T any] was more performant with respect to CPU and memory by 300% and 200%, respectively.
  • Because no boxing was needed to store an int in GVector[int], there was no need to allocate anything on the heap in order to box the ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.