You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
763 B

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