-
Notifications
You must be signed in to change notification settings - Fork 6
/
benchmark_test.go
93 lines (79 loc) · 3.13 KB
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package fasttld
import (
"fmt"
"testing"
"github.com/fatih/color"
joeguotldextract "github.com/joeguo/tldextract"
tld "github.com/jpillora/go-tld"
mjd2021usatldextract "github.com/mjd2021usa/tldextract"
)
func BenchmarkComparison(b *testing.B) {
var benchmarkURLs = []string{
"https://iupac.org/iupac-announces-the-2021-top-ten-emerging-technologies-in-chemistry/",
"https://www.google.com/maps/dir/Parliament+Place,+Parliament+House+Of+Singapore,+" +
"Singapore/Parliament+St,+London,+UK/@25.2440033,33.6721455,4z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x31d" +
"a19a0abd4d71d:0xeda26636dc4ea1dc!2m2!1d103.8504863!2d1.2891543!1m5!1m1!1s0x487604c5aaa7da5b:0xf13a2" +
"197d7e7dd26!2m2!1d-0.1260826!2d51.5017061!3e4",
"https://a.b.c.d.e.f.g.h.i.j.k.l.m.n.oo.pp.qqq.rrrr.ssssss.tttttttt.uuuuuuuuuuu.vvvvvvvvvvvvvvv.wwwwwwwwwwwwwwwwwwwwww.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.cc",
}
benchmarks := []struct {
name string
}{
{"GoFastTld"}, // this module
{"JPilloraGoTld"}, // github.com/jpillora/go-tld
{"JoeGuoTldExtract"}, // github.com/joeguo/tldextract
{"Mjd2021USATldExtract"}, // github.com/mjd2021usa/tldextract
}
cache := "/tmp/tld.cache"
for _, benchmarkURL := range benchmarkURLs {
for _, bm := range benchmarks {
if bm.name == "GoFastTld" {
testPSLFilePath, _ := getTestPSLFilePath()
GoFastTld, _ := New(SuffixListParams{
CacheFilePath: testPSLFilePath,
IncludePrivateSuffix: false,
})
b.Run(fmt.Sprint(bm.name), func(b *testing.B) {
for i := 0; i < b.N; i++ {
GoFastTld.Extract(URLParams{URL: benchmarkURL})
}
})
} else if bm.name == "JPilloraGoTld" {
// Provides the Port and Path subcomponents
// Cannot handle "+://google.com" and IP addresses
// Cannot handle urls without Scheme subcomponent
// Cannot handle trailing whitespace
b.Run(fmt.Sprint(bm.name), func(b *testing.B) {
for i := 0; i < b.N; i++ {
tld.Parse(benchmarkURL)
}
})
} else if bm.name == "JoeGuoTldExtract" {
JoeGuoTldExtract, _ := joeguotldextract.New(cache, false)
b.Run(fmt.Sprint(bm.name), func(b *testing.B) {
for i := 0; i < b.N; i++ {
JoeGuoTldExtract.Extract(benchmarkURL)
}
})
} else if bm.name == "Mjd2021USATldExtract" {
Mjd2021USATldExtract, _ := mjd2021usatldextract.New(cache, false)
b.Run(fmt.Sprint(bm.name), func(b *testing.B) {
for i := 0; i < b.N; i++ {
Mjd2021USATldExtract.Extract(benchmarkURL)
}
})
}
}
color.New().Println()
color.New(color.FgHiGreen, color.Bold).Print("Benchmarks completed for URL : ")
color.New(color.FgHiBlue).Println(benchmarkURL)
color.New(color.FgHiWhite).Println("=======")
}
}
/*
Omitted modules
github.com/M507/tlde | Almost exactly the same as github.com/joeguo/tldextract
github.com/ImVexed/fasturl | Fast, but cannot extract eTLDs
github.com/weppos/publicsuffix-go | Cannot handle full URLs with scheme (i.e. https:// ftp:// etc.)
github.com/forease/gotld | Does not extract subdomain properly and cannot handle ip addresses
*/