80: def test_measurement(thread_count, action_count)
81: q = Queue.new
82: q.extend DeepTest::Metrics::QueueLockWaitTimeMeasurement
83:
84: threads = []
85: thread_count.times do
86: threads << Thread.new do
87: action_count.times do |i|
88: show_progress ".", action_count, i
89: q.push 1
90: end
91: end
92: end
93:
94: thread_count.times do
95: threads << Thread.new do
96: action_count.times do |i|
97: show_progress "-", action_count, i
98: if rand(2) == 0
99: begin
100: q.pop(true)
101: rescue ThreadError
102: end
103: else
104: begin
105: Timeout.timeout(0.01) do
106: q.pop
107: end
108: rescue Timeout::Error
109: break
110: end
111: end
112: end
113: end
114: end
115:
116: threads.each {|t| t.join}
117:
118: puts
119: puts "Push Time: #{q.total_push_time}"
120: puts "Pop Time: #{q.total_pop_time}"
121: end