2
0

Add benchmark

This commit is contained in:
Miloš Mileusnić
2022-06-23 22:57:15 +02:00
parent f5766bcb28
commit c2a5d8c196
+11 -1
View File
@@ -8,7 +8,6 @@ import (
ua "github.com/mileusna/useragent" ua "github.com/mileusna/useragent"
) )
func TestParse(t *testing.T) {
var testTable = [][]string{ var testTable = [][]string{
// useragent, name, version, mobile, os // useragent, name, version, mobile, os
// Mac // Mac
@@ -70,6 +69,7 @@ func TestParse(t *testing.T) {
{"Twitterbot/1.0", ua.Twitterbot, "1.0", ua.Applebot, ""}, {"Twitterbot/1.0", ua.Twitterbot, "1.0", ua.Applebot, ""},
{"facebookexternalhit/1.1", ua.FacebookExternalHit, "1.1", "bot", ""}, {"facebookexternalhit/1.1", ua.FacebookExternalHit, "1.1", "bot", ""},
{"Mozilla/5.0 (compatible; SemrushBot/7~bl; +http://www.semrush.com/bot.html", "SemrushBot", "7~bl", "bot", ""}, {"Mozilla/5.0 (compatible; SemrushBot/7~bl; +http://www.semrush.com/bot.html", "SemrushBot", "7~bl", "bot", ""},
{"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.268", "YandexBot", "3.0", "bot", ""},
// Brave // Brave
{"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/87.0.4280.101 Safari/537.36", ua.Chrome, "87.0.4280.101", "desktop", ua.Linux}, {"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/87.0.4280.101 Safari/537.36", ua.Chrome, "87.0.4280.101", "desktop", ua.Linux},
@@ -94,6 +94,7 @@ func TestParse(t *testing.T) {
//Mozilla/5.0 (Macintosh; Intel Mac OS Xt 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.6.0 Chrome/45.0.2454.101 Safari/537.36 //Mozilla/5.0 (Macintosh; Intel Mac OS Xt 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.6.0 Chrome/45.0.2454.101 Safari/537.36
} }
func TestParse(t *testing.T) {
for _, test := range testTable { for _, test := range testTable {
ua := ua.Parse(test[0]) ua := ua.Parse(test[0])
if ua.Name != test[1] { if ua.Name != test[1] {
@@ -122,7 +123,16 @@ func TestParse(t *testing.T) {
//fmt.Println(ua.OS, ua.OSVersion, ua.Device) //fmt.Println(ua.OS, ua.OSVersion, ua.Device)
} }
}
var testUA ua.UserAgent
func BenchmarkUserAgent(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testTable {
testUA = ua.Parse(test[0])
}
}
} }
func ExampleParse() { func ExampleParse() {