MCPcopy Index your code
hub / github.com/PuerkitoBio/goquery / BenchmarkMetalReviewExample

Function BenchmarkMetalReviewExample

bench_example_test.go:10–40  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

8)
9
10func BenchmarkMetalReviewExample(b *testing.B) {
11 var n int
12 var builder strings.Builder
13
14 b.StopTimer()
15 doc := loadDoc("metalreview.html")
16 b.StartTimer()
17 for i := 0; i < b.N; i++ {
18 doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
19 var band, title string
20 var score float64
21 var e error
22
23 n++
24 // For each item found, get the band, title and score, and print it
25 band = s.Find("strong").Text()
26 title = s.Find("em").Text()
27 if score, e = strconv.ParseFloat(s.Find(".score").Text(), 64); e != nil {
28 // Not a valid float, ignore score
29 if n <= 4 {
30 builder.WriteString(fmt.Sprintf("Review %d: %s - %s.\n", i, band, title))
31 }
32 } else {
33 // Print all, including score
34 if n <= 4 {
35 builder.WriteString(fmt.Sprintf("Review %d: %s - %s (%2.1f).\n", i, band, title, score))
36 }
37 }
38 })
39 }
40}

Callers

nothing calls this directly

Calls 4

loadDocFunction · 0.85
EachMethod · 0.80
FindMethod · 0.80
TextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…