<commit_before>package mathgl_test

import (
	"github.com/Jragonmiris/mathgl"
	"testing"
)

// Benchmarks a standard model-view-projection multiplication
func BenchmarkMVPMul(b *testing.B) {
	b.StopTimer()
	
	M := mathgl.Identity(4, mathgl.FLOAT64)
	V := mathgl.LookAt(4., 3., 3., 0., 0., 0., 0, 1., 0)
	P := mathgl.Perspective(45.0, 4./3., .1, 100.0)

	b.StartTimer()

	for i := 0; i < b.N; i++ {
		P.Mul(V).Mul(M)
		//MVP.AsCMOArray(mathgl.FLOAT32)
	}
}

// Benchmarks creation AND multiplication of a standard MVP matrix
func BenchmarkMVPMake(b *testing.B) {

	for i := 0; i < b.N; i++ {
	
		M := mathgl.Identity(4, mathgl.FLOAT64)
		V := mathgl.LookAt(4., 3., 3., 0., 0., 0., 0, 1., 0)
		P := mathgl.Perspective(45.0, 4./3., .1, 100.0)
		P.Mul(V).Mul(M)
	}
}

func BenchmarkPerspective(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.Perspective(45.0, 4./3., .1, 100.0)
	}
}

func BenchmarkIdentity(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.Identity(4, mathgl.FLOAT64)
	}
}

// This should be the most expensive because of all the cross products and multiplications it does
func BenchmarkLookAt(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.LookAt(4., 3., 3., 0., 0., 0., 0, 1., 0)
	}
}

func BenchmarkLookAtV(b *testing.B) {
	b.StopTimer()
	eye,_ := mathgl.InferVectorOf(4., 3., 3.)
	center,_ := mathgl.InferVectorOf(0.,0.,0.)
	up,_ := mathgl.InferVectorOf(0.,1.,0.)

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		mathgl.LookAtV(*eye, *center, *up)
	}
}

func BenchmarkVectorOf(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.VectorOf([]mathgl.Scalar {
			mathgl.MakeScalar(4.0, mathgl.FLOAT64),
			mathgl.MakeScalar(3.1, mathgl.FLOAT64),
			mathgl.MakeScalar(9.2, mathgl.FLOAT64),
			mathgl.MakeScalar(1.0, mathgl.FLOAT64)}, mathgl.FLOAT64)
	}<commit_msg>Added comment<commit_after>package mathgl_test

import (
	"github.com/Jragonmiris/mathgl"
	"testing"
)

// Benchmarks a standard model-view-projection multiplication
func BenchmarkMVPMul(b *testing.B) {
	b.StopTimer()
	
	M := mathgl.Identity(4, mathgl.FLOAT64)
	V := mathgl.LookAt(4., 3., 3., 0., 0., 0., 0, 1., 0)
	P := mathgl.Perspective(45.0, 4./3., .1, 100.0)

	b.StartTimer()

	for i := 0; i < b.N; i++ {
		P.Mul(V).Mul(M)
		//MVP.AsCMOArray(mathgl.FLOAT32)
	}
}

// Benchmarks creation AND multiplication of a standard MVP matrix
func BenchmarkMVPMake(b *testing.B) {

	for i := 0; i < b.N; i++ {
	
		M := mathgl.Identity(4, mathgl.FLOAT64)
		V := mathgl.LookAt(4., 3., 3., 0., 0., 0., 0, 1., 0)
		P := mathgl.Perspective(45.0, 4./3., .1, 100.0)
		P.Mul(V).Mul(M)
	}
}

func BenchmarkPerspective(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.Perspective(45.0, 4./3., .1, 100.0)
	}
}

func BenchmarkIdentity(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.Identity(4, mathgl.FLOAT64)
	}
}

// This should be the most expensive because of all the cross products and multiplications it does
func BenchmarkLookAt(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.LookAt(4., 3., 3., 0., 0., 0., 0, 1., 0)
	}
}

func BenchmarkLookAtV(b *testing.B) {
	b.StopTimer()
	eye,_ := mathgl.InferVectorOf(4., 3., 3.)
	center,_ := mathgl.InferVectorOf(0.,0.,0.)
	up,_ := mathgl.InferVectorOf(0.,1.,0.)

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		mathgl.LookAtV(*eye, *center, *up)
	}
}

// This benchmark may not be fair compared to Infer, not sure
func BenchmarkVectorOf(b *testing.B) {
	for i := 0; i < b.N; i++ {
		mathgl.VectorOf([]mathgl.Scalar {
			mathgl.MakeScalar(4.0, mathgl.FLOAT64),
			mathgl.MakeScalar(3.1, mathgl.FLOAT64),
			mathgl.MakeScalar(9.2, mathgl.FLOAT64),
			mathgl.MakeScalar(1.0, mathgl.FLOAT64)}, mathgl.FLOAT64)
	}
{'fraction_non_alphanumeric': 0.19642857142857142, 'fraction_numerical': 0.056043956043956046, 'mean_word_length': 3.2141203703703702, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4968513', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1573, 'n_words': 366}