func_call_benchmark_test.go 340 B

1234567891011121314151617181920212223242526
  1. package main
  2. import "testing"
  3. func BenchmarkFuncCallSpeedWithInner(b *testing.B) {
  4. for i := 0; i < b.N; i++ {
  5. withInner()
  6. }
  7. }
  8. func BenchmarkFuncCallSpeedWithoutInner(b *testing.B) {
  9. for i := 0; i < b.N; i++ {
  10. withInner()
  11. }
  12. }
  13. func withInner() int {
  14. return func() int {
  15. return 10
  16. }()
  17. }
  18. func withoutInner() int {
  19. return 10
  20. }