-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0bd13b
commit c5125b1
Showing
32 changed files
with
12,440 additions
and
10,590 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Interface vs Direct Method Call | ||
headline: A benchmark to compare the performance of interface vs direct method calls in Go. | ||
description: > | ||
This benchmark compares the performance of interface vs direct method calls in Go. | ||
Each benchmark creates a struct, containing a single method. | ||
It will then call the method on the struct, either directly or via an interface. | ||
tags: | ||
- interface | ||
- struct | ||
|
||
contributors: | ||
- MarvinJWendt | ||
|
||
meta: | ||
- implementation: Interface Method Call | ||
description: > | ||
This benchmark calls the method on the struct via an interface. | ||
- implementation: Direct Method Call | ||
description: > | ||
This benchmark calls the method on the struct directly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package interface_vs_direct_method_call | ||
|
||
import "testing" | ||
|
||
type DirectStruct struct{} | ||
|
||
func (m DirectStruct) Method() {} | ||
|
||
func BenchmarkDirectMethodCall_run(b *testing.B) { | ||
s := DirectStruct{} | ||
for i := 0; i < b.N; i++ { | ||
s.Method() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
benchmarks/interface-vs-direct-method-call/interface_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package interface_vs_direct_method_call | ||
|
||
import "testing" | ||
|
||
type Interface interface { | ||
Method() | ||
} | ||
|
||
type InterfaceStruct struct{} | ||
|
||
func (m InterfaceStruct) Method() {} | ||
|
||
func BenchmarkInterfaceMethodCall_run(b *testing.B) { | ||
var s Interface = InterfaceStruct{} | ||
for i := 0; i < b.N; i++ { | ||
s.Method() | ||
} | ||
} |
180 changes: 180 additions & 0 deletions
180
benchmarks/interface-vs-direct-method-call/output.bench
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 1000 0.4500 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 1000 0.4800 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 1000 0.5100 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 1000 0.4500 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 1000 0.5300 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 1000 0.5000 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 1000 1.820 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 1000 1.820 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 1000 1.850 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 1000 1.830 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 1000 1.860 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 1000 1.850 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.017s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 2000 0.3600 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 2000 0.3800 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 2000 0.3850 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 2000 0.6300 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 2000 0.3850 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 2000 0.3850 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 2000 1.710 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 2000 1.720 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 2000 1.800 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 2000 1.745 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 2000 1.740 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 2000 1.730 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 3000 0.5533 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 3000 0.3333 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 3000 0.3467 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 3000 0.3467 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 3000 0.3467 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 3000 0.3500 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 3000 1.677 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 3000 1.690 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 3000 1.690 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 3000 1.690 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 3000 1.697 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 3000 1.690 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 4000 0.3150 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 4000 0.3225 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 4000 0.3225 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 4000 0.3325 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 4000 0.3250 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 4000 0.3250 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 4000 1.670 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 4000 1.680 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 4000 1.675 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 4000 1.673 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 4000 1.675 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 4000 1.675 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 5000 0.3040 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 5000 0.3160 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 5000 0.3220 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 5000 0.3540 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 5000 0.3100 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 5000 0.3200 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 5000 1.664 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 5000 1.664 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 5000 1.672 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 5000 1.670 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 5000 1.666 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 5000 1.672 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 6000 0.2983 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 6000 0.2983 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 6000 0.3033 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 6000 0.3050 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 6000 0.3100 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 6000 0.3117 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 6000 1.652 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 6000 1.652 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 6000 1.660 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 6000 1.660 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 6000 1.658 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 6000 1.658 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 7000 0.3300 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 7000 0.4971 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 7000 0.4671 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 7000 0.3043 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 7000 0.2986 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 7000 0.3014 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 7000 1.646 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 7000 2.021 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 7000 1.649 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 7000 1.651 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 7000 1.653 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 7000 1.650 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.017s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 8000 0.2925 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 8000 0.3013 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 8000 0.2950 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 8000 0.3013 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 8000 0.2938 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 8000 0.3000 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 8000 1.642 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 8000 1.651 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 8000 1.650 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 8000 1.651 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 8000 1.647 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 8000 1.647 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 9000 0.2900 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 9000 0.2900 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 9000 0.2889 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 9000 0.2944 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 9000 0.2956 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 9000 0.2911 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 9000 1.639 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 9000 3.289 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 9000 1.641 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 9000 1.644 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 9000 1.643 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 9000 1.644 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call | ||
cpu: AMD Ryzen 9 3950X 16-Core Processor | ||
BenchmarkDirectMethodCall_run 10000 0.2870 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-2 10000 0.2930 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-4 10000 0.2940 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-8 10000 0.2940 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-16 10000 0.2950 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDirectMethodCall_run-32 10000 0.2930 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run 10000 1.639 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-2 10000 1.643 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-4 10000 1.859 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-8 10000 1.642 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-16 10000 1.648 ns/op 0 B/op 0 allocs/op | ||
BenchmarkInterfaceMethodCall_run-32 10000 1.647 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok github.com/go-benchmarks/benchmarks/benchmarks/interface-vs-direct-method-call 0.016s |
Oops, something went wrong.