File: int_allocator.rb

package info (click to toggle)
ruby-amq-protocol 2.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 504 kB
  • sloc: ruby: 5,222; python: 248; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 698 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))

require 'amq/int_allocator'
require "benchmark"

allocator = AMQ::IntAllocator.new(1,65535)
mutex = Mutex.new

Benchmark.bm do |x|


  x.report("allocate") do
    allocator = AMQ::IntAllocator.new(1,65535)
    1.upto(65534) do |i|
      mutex.synchronize do
        n = allocator.allocate
        raise 'it be broke' unless n == i
      end
    end
  end

  x.report("allocate_with_release") do
    allocator = AMQ::IntAllocator.new(1,65535)
    1.upto(65534) do |i|
      mutex.synchronize do
        n = allocator.allocate
        if i % 5 == 0
          allocator.release(n)
        end
      end
    end
  end

end