1package goquery 2 3import ( 4 "testing" 5) 6 7func BenchmarkAttr(b *testing.B) { 8 var s string 9 10 b.StopTimer() 11 sel := DocW().Find("h1") 12 b.StartTimer() 13 for i := 0; i < b.N; i++ { 14 s, _ = sel.Attr("id") 15 } 16 if s != "firstHeading" { 17 b.Fatalf("want firstHeading, got %q", s) 18 } 19} 20 21func BenchmarkText(b *testing.B) { 22 b.StopTimer() 23 sel := DocW().Find("h2") 24 b.StartTimer() 25 for i := 0; i < b.N; i++ { 26 sel.Text() 27 } 28} 29 30func BenchmarkLength(b *testing.B) { 31 var n int 32 33 b.StopTimer() 34 sel := DocW().Find("h2") 35 b.StartTimer() 36 for i := 0; i < b.N; i++ { 37 n = sel.Length() 38 } 39 if n != 14 { 40 b.Fatalf("want 14, got %d", n) 41 } 42} 43 44func BenchmarkHtml(b *testing.B) { 45 b.StopTimer() 46 sel := DocW().Find("h2") 47 b.StartTimer() 48 for i := 0; i < b.N; i++ { 49 sel.Html() 50 } 51} 52