Add benchmark
This commit is contained in:
+13
-3
@@ -8,8 +8,7 @@ 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
|
||||||
{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8", ua.Safari, "10.1.2", "desktop", "macOS"},
|
{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8", ua.Safari, "10.1.2", "desktop", "macOS"},
|
||||||
@@ -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},
|
||||||
@@ -92,8 +92,9 @@ func TestParse(t *testing.T) {
|
|||||||
//GooglePlus "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Google (+https://developers.google.com/+/web/snippet/)"
|
//GooglePlus "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Google (+https://developers.google.com/+/web/snippet/)"
|
||||||
//Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5 (Applebot/0.1; +http://www.apple.com/go/applebot)
|
//Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5 (Applebot/0.1; +http://www.apple.com/go/applebot)
|
||||||
//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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user