Top Level Namespace

Defined Under Namespace

Modules: DeepTest, Spec, Test

Instance Method Summary collapse

Instance Method Details

#show_progress(s, total, current) ⇒ Object



123
124
125
126
127
128
# File 'lib/deep_test/metrics/queue_lock_wait_time_measurement.rb', line 123

def show_progress(s, total, current)
  if (current % (total / 5)) == 0
    $stdout.print s
    $stdout.flush
  end
end

#test_measurement(thread_count, action_count) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/deep_test/metrics/queue_lock_wait_time_measurement.rb', line 80

def test_measurement(thread_count, action_count)
  q = Queue.new
  q.extend DeepTest::Metrics::QueueLockWaitTimeMeasurement

  threads = []
  thread_count.times do
    threads << Thread.new do
      action_count.times do |i|
        show_progress ".", action_count, i
        q.push 1
      end
    end
  end

  thread_count.times do
    threads << Thread.new do
      action_count.times do |i|
        show_progress "-", action_count, i
        if rand(2) == 0
          begin
            q.pop(true)
          rescue ThreadError
          end
        else
          begin
            Timeout.timeout(0.01) do
              q.pop
            end
          rescue Timeout::Error
            break
          end
        end
      end
    end
  end

  threads.each {|t| t.join}

  puts
  puts "Push Time: #{q.total_push_time}"
  puts "Pop Time:  #{q.total_pop_time}"
end