<commit_before>// Copyright 2017 phcurtis fn Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fn_test

import (
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"strings"
	"testing"

	"github.com/phcurtis/fn"
)

func BenchmarkVarious(b *testing.B) {
	defer func() {
		fn.LogSetFlags(fn.LflagsDef)
		fn.LogSetOutput(os.Stdout)
	}()

	b.Run("fn.Cur............", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.Cur()
		}
	})
	b.Run("fn.LvlBase(Lme)...", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.LvlBase(fn.Lme)
		}
	})
	b.Run("fn.LvlCStk(Lme)...", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.LvlCStk(fn.Lme)
		}
	})
	b.Run("fn.CStk...........", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.CStk()
		}
	})
}

type f1Struct struct {
	cnt    int
	invoke int
	total  int
}

var f1s f1Struct

func f1(b *testing.B) {
	if f1s.cnt < f1s.invoke {
		f1s.cnt++
		f1(b)
	} else {
		deep := strings.Count(fn.CStk(), "<--") + 1
		if deep != f1s.total {
			b.Fatalf("wrong invocations: deep:%d invoke:%d total:%d", deep, f1s.invoke, f1s.total)
		}
	}
}

func f1main(total, invoke int, b *testing.B) {
	mintot := total - invoke + 3
	if total < mintot || total > fn.LvlCStkMax {
		b.Fatalf("total:%d is out of range[%d-%d]\n", total, mintot, fn.LvlCStkMax)
	}
	f1s.total = total
	f1s.invoke = invoke - 1 // since f1main is already 1 deep
	f1s.cnt = 1
	if f1s.invoke-f1s.cnt > 0 {
		f1(b)
	}
}

func Benchmark_cstkdepth(b *testing.B) {
	deepAdj := strings.Count(fn.CStk(), "<--") + 1 // add 1 to separator count
	tests := []struct {
		name string
		deep int
	}{
		{"fn.CStk.~10 deep..", 10},
		{"fn.CStk.~20 deep..", 20},
		{"fn.CStk.~30 deep..", 30},
		{"fn.CStk.~40 deep..", 40},
		{"fn.CStk.~50 deep..", 50},
		{"fn.CStk.~100deep..", 100},
		{"fn.CStk.~200deep..", 200},
		{"fn.CStk.~250deep..", 250},
		{"fn.CStk.~500deep..", 500},
	}
	for _, v := range tests {<commit_msg>test condition adjusted<commit_after>// Copyright 2017 phcurtis fn Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fn_test

import (
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"strings"
	"testing"

	"github.com/phcurtis/fn"
)

func BenchmarkVarious(b *testing.B) {
	defer func() {
		fn.LogSetFlags(fn.LflagsDef)
		fn.LogSetOutput(os.Stdout)
	}()

	b.Run("fn.Cur............", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.Cur()
		}
	})
	b.Run("fn.LvlBase(Lme)...", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.LvlBase(fn.Lme)
		}
	})
	b.Run("fn.LvlCStk(Lme)...", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.LvlCStk(fn.Lme)
		}
	})
	b.Run("fn.CStk...........", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			fn.CStk()
		}
	})
}

type f1Struct struct {
	cnt    int
	invoke int
	total  int
}

var f1s f1Struct

func f1(b *testing.B) {
	if f1s.cnt < f1s.invoke {
		f1s.cnt++
		f1(b)
	} else {
		deep := strings.Count(fn.CStk(), "<--") + 1
		if deep != f1s.total {
			b.Fatalf("wrong invocations: deep:%d invoke:%d total:%d", deep, f1s.invoke, f1s.total)
		}
	}
}

func f1main(total, invoke int, b *testing.B) {
	mintot := 4
	if total < mintot || total > fn.LvlCStkMax {
		b.Fatalf("total:%d is out of range[%d-%d]\n", total, mintot, fn.LvlCStkMax)
	}
	f1s.total = total
	f1s.invoke = invoke - 1 // since f1main is already 1 deep
	f1s.cnt = 1
	if f1s.invoke-f1s.cnt > 0 {
		f1(b)
	}
}

func Benchmark_cstkdepth(b *testing.B) {
	deepAdj := strings.Count(fn.CStk(), "<--") + 1 // add 1 to separator count
	tests := []struct {
		name string
		deep int
	}{
		{"fn.CStk.~10 deep..", 10},
		{"fn.CStk.~20 deep..", 20},
		{"fn.CStk.~30 deep..", 30},
		{"fn.CStk.~40 deep..", 40},
		{"fn.CStk.~50 deep..", 50},
		{"fn.CStk.~100deep..", 100},
		{"fn.CStk.~200deep..", 200},
		{"fn.CStk.~250deep..", 250},
		{"fn.CStk.~500deep..", 500},
	}
	for _, v := range tests {
{'fraction_non_alphanumeric': 0.21960391075457508, 'fraction_numerical': 0.039608924542491854, 'mean_word_length': 2.6605504587155964, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, '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': '3989843', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1840, 'n_words': 412}