mirror of
https://github.com/miniflux/v2.git
synced 2025-07-02 16:38:37 +00:00
First commit
This commit is contained in:
commit
8ffb773f43
2121 changed files with 1118910 additions and 0 deletions
40
vendor/github.com/PuerkitoBio/goquery/bench_example_test.go
generated
vendored
Normal file
40
vendor/github.com/PuerkitoBio/goquery/bench_example_test.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
package goquery
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkMetalReviewExample(b *testing.B) {
|
||||
var n int
|
||||
var buf bytes.Buffer
|
||||
|
||||
b.StopTimer()
|
||||
doc := loadDoc("metalreview.html")
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
|
||||
var band, title string
|
||||
var score float64
|
||||
var e error
|
||||
|
||||
n++
|
||||
// For each item found, get the band, title and score, and print it
|
||||
band = s.Find("strong").Text()
|
||||
title = s.Find("em").Text()
|
||||
if score, e = strconv.ParseFloat(s.Find(".score").Text(), 64); e != nil {
|
||||
// Not a valid float, ignore score
|
||||
if n <= 4 {
|
||||
buf.WriteString(fmt.Sprintf("Review %d: %s - %s.\n", i, band, title))
|
||||
}
|
||||
} else {
|
||||
// Print all, including score
|
||||
if n <= 4 {
|
||||
buf.WriteString(fmt.Sprintf("Review %d: %s - %s (%2.1f).\n", i, band, title, score))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue