github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/goquery/bench_property_test.go (about) 1 package goquery 2 3 import ( 4 "testing" 5 ) 6 7 func 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 b.Logf("Attr=%s", s) 17 } 18 19 func BenchmarkText(b *testing.B) { 20 b.StopTimer() 21 sel := DocW().Find("h2") 22 b.StartTimer() 23 for i := 0; i < b.N; i++ { 24 sel.Text() 25 } 26 } 27 28 func BenchmarkLength(b *testing.B) { 29 var n int 30 31 b.StopTimer() 32 sel := DocW().Find("h2") 33 b.StartTimer() 34 for i := 0; i < b.N; i++ { 35 n = sel.Length() 36 } 37 b.Logf("Length=%d", n) 38 } 39 40 func BenchmarkHtml(b *testing.B) { 41 b.StopTimer() 42 sel := DocW().Find("h2") 43 b.StartTimer() 44 for i := 0; i < b.N; i++ { 45 sel.Html() 46 } 47 }