# Generics benchmarks

**URL:** <https://forum.golangbridge.org/t/generics-benchmarks/38939>\
**Category:** Technical Discussion\
**Created:** [June 1, 2025, 5:47pm UTC](https://forum.golangbridge.org/t/generics-benchmarks/38939 "2025-06-01T17:47:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwr](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mwr](https://forum.golangbridge.org/u/mwr)\
**Post date:** [June 1, 2025, 5:47pm UTC](https://forum.golangbridge.org/t/generics-benchmarks/38939/1 "2025-06-01T17:47:53Z")

</div>

Similar results were obtained for different platforms and architectures.  
It’s not a language problem, is it?

``  
type Signed interface {  
~int | ~int8 | ~int16 | ~int32 | ~int64;  
}

type Getter interface {  
Get(int) int  
}

type GetObj struct {}

func (o \*GetObj) Get(i int) int {  
return i \* i  
}

type GenGetter[T Signed] interface {  
Get(T) T  
}

type GenGetObj[T Signed] struct {}

func (o \*GenGetObj[T]) Get(i T) T {  
return i \* i  
}

func reg(obj \*GetObj, i int) int {  
return obj.Get(i)  
}

func iface(obj Getter, i int) int {  
return obj.Get(i)  
}

func gen[T Signed](obj GenGetter[T], i T) T {  
return obj.Get(i)  
}

func BenchmarkReg(b \*testing.B) {  
var obj = &GetObj{}  
var i = 0  
for b.Loop() {  
reg(obj, i)  
i++  
}  
}

func BenchmarkIface(b \*testing.B) {  
var obj = &GetObj{}  
var i = 0  
for b.Loop() {  
iface(obj, i)  
i++  
}  
}

func BenchmarkGen(b \*testing.B) {  
var obj = &GenGetObj[int]{}  
var i = 0  
for b.Loop() {  
gen(obj, i)  
i++  
}  
}

```auto

```

BenchmarkReg-4 441981427 2.743 ns/op  
BenchmarkReg-4 428439991 2.810 ns/op  
BenchmarkReg-4 422647483 2.775 ns/op  
BenchmarkReg-4 414114366 2.839 ns/op  
BenchmarkReg-4 429933127 2.720 ns/op  
BenchmarkIface-4 260450607 4.558 ns/op  
BenchmarkIface-4 258018102 4.488 ns/op  
BenchmarkIface-4 248518578 4.655 ns/op  
BenchmarkIface-4 257133632 4.517 ns/op  
BenchmarkIface-4 272843784 4.386 ns/op  
BenchmarkGen-4 245088946 4.932 ns/op  
BenchmarkGen-4 248562715 4.826 ns/op  
BenchmarkGen-4 245683516 4.812 ns/op  
BenchmarkGen-4 239086440 4.948 ns/op  
BenchmarkGen-4 228736507 5.074 ns/op

```auto

```

---

<div class="post-metadata">

**Author:** ![eik](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/eik/32/16550_2.png) [@eik](https://forum.golangbridge.org/u/eik)\
**Post date:** [June 4, 2025, 10:43am UTC](https://forum.golangbridge.org/t/generics-benchmarks/38939/3 "2025-06-04T10:43:34Z")

</div>

> [@mwr](#):
>
> Similar results were obtained for different platforms and architectures.  
> It’s not a language problem, is it?

What exactly did you try and what is your problem with the results?

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [September 2, 2025, 10:43am UTC](https://forum.golangbridge.org/t/generics-benchmarks/38939/4 "2025-09-02T10:43:41Z")

</div>

Closed on September 2, 2025, 10:43am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
