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.

46 lines
771 B

  1. package clist
  2. import "testing"
  3. func BenchmarkDetaching(b *testing.B) {
  4. lst := New()
  5. for i := 0; i < b.N+1; i++ {
  6. lst.PushBack(i)
  7. }
  8. start := lst.Front()
  9. nxt := start.Next()
  10. b.ResetTimer()
  11. for i := 0; i < b.N; i++ {
  12. start.removed = true
  13. start.detachNext()
  14. start.DetachPrev()
  15. tmp := nxt
  16. nxt = nxt.Next()
  17. start = tmp
  18. }
  19. }
  20. // This is used to benchmark the time of RMutex.
  21. func BenchmarkRemoved(b *testing.B) {
  22. lst := New()
  23. for i := 0; i < b.N+1; i++ {
  24. lst.PushBack(i)
  25. }
  26. start := lst.Front()
  27. nxt := start.Next()
  28. b.ResetTimer()
  29. for i := 0; i < b.N; i++ {
  30. start.Removed()
  31. tmp := nxt
  32. nxt = nxt.Next()
  33. start = tmp
  34. }
  35. }
  36. func BenchmarkPushBack(b *testing.B) {
  37. lst := New()
  38. b.ResetTimer()
  39. for i := 0; i < b.N; i++ {
  40. lst.PushBack(i)
  41. }
  42. }