mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-07-12 12:19:46 +00:00
bench: small refactoring extracting table
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
@ -2,6 +2,7 @@ package enry
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -110,11 +111,9 @@ func getSamples(dir string) ([]*sample, error) {
|
|||||||
filename: path,
|
filename: path,
|
||||||
content: content,
|
content: content,
|
||||||
}
|
}
|
||||||
|
|
||||||
samples = append(samples, s)
|
samples = append(samples, s)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return samples, err
|
return samples, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,17 +156,7 @@ func BenchmarkStrategiesTotal(b *testing.B) {
|
|||||||
b.SkipNow()
|
b.SkipNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
benchmarks := []struct {
|
benchmarks := benchmarkForAllStrategies("TOTAL")
|
||||||
name string
|
|
||||||
strategy Strategy
|
|
||||||
candidates []string
|
|
||||||
}{
|
|
||||||
{name: "GetLanguagesByModeline()_TOTAL", strategy: GetLanguagesByModeline},
|
|
||||||
{name: "GetLanguagesByFilename()_TOTAL", strategy: GetLanguagesByFilename},
|
|
||||||
{name: "GetLanguagesByShebang()_TOTAL", strategy: GetLanguagesByShebang},
|
|
||||||
{name: "GetLanguagesByExtension()_TOTAL", strategy: GetLanguagesByExtension},
|
|
||||||
{name: "GetLanguagesByContent()_TOTAL", strategy: GetLanguagesByContent},
|
|
||||||
}
|
|
||||||
|
|
||||||
var o []string
|
var o []string
|
||||||
for _, benchmark := range benchmarks {
|
for _, benchmark := range benchmarks {
|
||||||
@ -222,17 +211,7 @@ func BenchmarkStrategiesPerSample(b *testing.B) {
|
|||||||
b.SkipNow()
|
b.SkipNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
benchmarks := []struct {
|
benchmarks := benchmarkForAllStrategies("SAMPLE")
|
||||||
name string
|
|
||||||
strategy Strategy
|
|
||||||
candidates []string
|
|
||||||
}{
|
|
||||||
{name: "GetLanguagesByModeline()_SAMPLE_", strategy: GetLanguagesByModeline},
|
|
||||||
{name: "GetLanguagesByFilename()_SAMPLE_", strategy: GetLanguagesByFilename},
|
|
||||||
{name: "GetLanguagesByShebang()_SAMPLE_", strategy: GetLanguagesByShebang},
|
|
||||||
{name: "GetLanguagesByExtension()_SAMPLE_", strategy: GetLanguagesByExtension},
|
|
||||||
{name: "GetLanguagesByContent()_SAMPLE_", strategy: GetLanguagesByContent},
|
|
||||||
}
|
|
||||||
|
|
||||||
var o []string
|
var o []string
|
||||||
for _, benchmark := range benchmarks {
|
for _, benchmark := range benchmarks {
|
||||||
@ -247,3 +226,19 @@ func BenchmarkStrategiesPerSample(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type strategyName struct {
|
||||||
|
name string
|
||||||
|
strategy Strategy
|
||||||
|
candidates []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkForAllStrategies(class string) []strategyName {
|
||||||
|
return []strategyName{
|
||||||
|
{name: fmt.Sprintf("GetLanguagesByModeline()_%s_", class), strategy: GetLanguagesByModeline},
|
||||||
|
{name: fmt.Sprintf("GetLanguagesByFilename()_%s_", class), strategy: GetLanguagesByFilename},
|
||||||
|
{name: fmt.Sprintf("GetLanguagesByShebang()_%s_", class), strategy: GetLanguagesByShebang},
|
||||||
|
{name: fmt.Sprintf("GetLanguagesByExtension()_%s_", class), strategy: GetLanguagesByExtension},
|
||||||
|
{name: fmt.Sprintf("GetLanguagesByContent()_%s_", class), strategy: GetLanguagesByContent},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user