<commit_before>package main

import (
	"bytes"
	"fmt"
	"github.com/bbiskup/golang_benchmarks/pkg1"
	"strconv"
	"strings"
	"testing"
)

type S struct {
}

func (s *S) getValMethod(value int) int {
	return value + 1
}

func BenchmarkEmpty(b *testing.B) {
	for i := 0; i < b.N; i++ {

	}
}

type SI interface {
	getValMethod(value int) int
}

func BenchmarkAddLoop(b *testing.B) {
	var value int
	for i := 0; i < b.N; i++ {
		value++
	}
	_ = value
	// fmt.Printf("Value: %d\n", value)
}

func getValPlus1(val int) int {
	return val + 1
}

func BenchmarkFuncCallSamePkg(b *testing.B) {
	var value int
	for i := 0; i < b.N; i++ {
		value = getValPlus1(value)
	}
	_ = value
	//fmt.Printf("Value: %d\n", value)
}

func BenchmarkFuncCallByVar(b *testing.B) {
	fn := getValPlus1
	var value int
	for i := 0; i < b.N; i++ {
		value = fn(value)
	}
	_ = value
}

func BenchmarkStructMethodSamePkg(b *testing.B) {
	s := &S{}
	var value int
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		value = s.getValMethod(value)
	}
	_ = value
	// fmt.Printf("Value: %d\n", value)
}

func BenchmarkInterfaceMethodSamePkg(b *testing.B) {
	var si SI = &S{}
	var value int
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		value = si.getValMethod(value)<commit_msg>Added benchmarks for method calls on embedded structs<commit_after>package main

import (
	"bytes"
	"fmt"
	"github.com/bbiskup/golang_benchmarks/pkg1"
	"strconv"
	"strings"
	"testing"
)

type S struct {
}

func (s *S) getValMethod(value int) int {
	return value + 1
}

func BenchmarkEmpty(b *testing.B) {
	for i := 0; i < b.N; i++ {

	}
}

type SI interface {
	getValMethod(value int) int
}

type S2 struct {
	S
}

func BenchmarkAddLoop(b *testing.B) {
	var value int
	for i := 0; i < b.N; i++ {
		value++
	}
	_ = value
	// fmt.Printf("Value: %d\n", value)
}

func getValPlus1(val int) int {
	return val + 1
}

func BenchmarkFuncCallSamePkg(b *testing.B) {
	var value int
	for i := 0; i < b.N; i++ {
		value = getValPlus1(value)
	}
	_ = value
	//fmt.Printf("Value: %d\n", value)
}

func BenchmarkFuncCallByVar(b *testing.B) {
	fn := getValPlus1
	var value int
	for i := 0; i < b.N; i++ {
		value = fn(value)
	}
	_ = value
}

func BenchmarkStructMethodSamePkg(b *testing.B) {
	s := &S{}
	var value int
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		value = s.getValMethod(value)
	}
	_ = value
	// fmt.Printf("Value: %d\n", value)
}

func BenchmarkInterfaceMethodSamePkg(b *testing.B) {
	var si SI = &S{}
	var value int
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		value = si.getValMethod(value)
	}
	_ = value
	// fmt.Printf("Value: %d\n", value)
}

// Should take twice as long as long as method call
// on struct due to indirection (see above)
func BenchmarkStructMethodSamePkgViaEmbeddedImplicit(b *testing.B) {
	s2 := &S2{}
	var value int
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		value = s2.getValMethod(value)
	}
	_ = value
	// fmt.Printf("Value: %d\n", value)
}

func BenchmarkStructMethodSamePkgViaEmbeddedExplicit(b *testing.B) {
	s2 := &S2{}
	var value int
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		value = s2.S.getValMethod(value)
{'fraction_non_alphanumeric': 0.1615209619759506, 'fraction_numerical': 0.010724731881702957, 'mean_word_length': 3.298882681564246, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1488262', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1317, 'n_words': 339}