53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package opts_test
|
|
|
|
import (
|
|
"flag"
|
|
"testing"
|
|
|
|
"github.com/spf13/pflag"
|
|
"go.fifitido.net/cmd/opts"
|
|
)
|
|
|
|
var (
|
|
_ = flag.Int("port", 80, "port")
|
|
_ = flag.String("host", "localhost", "host")
|
|
_ = flag.Float64("float", 3.14, "float")
|
|
_ = flag.Bool("bool", true, "bool")
|
|
|
|
_ = pflag.IntP("port", "p", 80, "port")
|
|
_ = pflag.StringP("host", "h", "localhost", "host")
|
|
_ = pflag.Float64P("float", "f", 3.14, "float")
|
|
_ = pflag.BoolP("bool", "b", true, "bool")
|
|
|
|
io = opts.Int("port", "p", 80, "port")
|
|
so = opts.String("host", "h", "localhost", "host")
|
|
fo = opts.Float("float", "f", 3.14, "float")
|
|
bo = opts.Bool("bool", "b", true, "bool")
|
|
set = opts.Set{io, so, fo, bo}
|
|
)
|
|
|
|
func BenchmarkFlag(b *testing.B) {
|
|
args := []string{"-port", "8080", "-host", "localhost", "-float", "3.14", "-bool"}
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
flag.CommandLine.Parse(args)
|
|
}
|
|
}
|
|
|
|
func BenchmarkPflag(b *testing.B) {
|
|
args := []string{"-p", "8080", "-h", "localhost", "-f", "3.14", "-b"}
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
pflag.CommandLine.Parse(args)
|
|
}
|
|
}
|
|
|
|
func BenchmarkOpts(b *testing.B) {
|
|
args := []string{"-p", "8080", "-h", "localhost", "-f", "3.14", "-b"}
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
parser := opts.NewParser(args, set, false)
|
|
parser.Parse()
|
|
}
|
|
}
|