Ejemplo n.º 1
0
func (s *suite) BenchmarkPushPopFrontDeque(c *gc.C) {
	d := deque.New()
	for i := 0; i < c.N; i++ {
		d.PushFront(i)
	}
	for i := 0; i < c.N; i++ {
		_, _ = d.PopFront()
	}
}
Ejemplo n.º 2
0
func (s *suite) BenchmarkPushPopBackDeque(c *gc.C) {
	d := deque.New()
	for i := 0; i < c.N; i++ {
		d.PushBack(i)
	}
	for i := 0; i < c.N; i++ {
		_, _ = d.PopBack()
	}
}
Ejemplo n.º 3
0
func (w *BufferedLogWriter) loop() {
	buffer := deque.New()
	var outCh LogRecordCh // Output channel - set when there's something to send.
	var outRec *LogRecord // Next LogRecord to send to the output channel.

	for {
		// If there's something in the buffer and there's nothing
		// queued up to send, set up the next LogRecord to send.
		if outCh == nil {
			if item, haveItem := buffer.PopFront(); haveItem {
				outRec = item.(*LogRecord)
				outCh = w.out
			}
		}

		select {
		case inRec, ok := <-w.in:
			if !ok {
				// Input channel has been closed; finish up.
				close(w.out)
				return
			}

			buffer.PushBack(inRec)

			if buffer.Len() > w.maxLen {
				// The buffer has exceeded the limit - discard the
				// next LogRecord from the front of the queue.
				buffer.PopFront()
				outRec.DroppedAfter++
			}

		case outCh <- outRec:
			outCh = nil // Signal that send happened.
		}
	}

}
Ejemplo n.º 4
0
func (s *suite) SetUpTest(c *gc.C) {
	s.deque = deque.New()
}