File: synchronized_sorted_set.rb

package info (click to toggle)
ruby-bunny 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: ruby: 10,256; sh: 70; makefile: 8
file content (53 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
# encoding: utf-8

require "rubygems"
require "sorted_set"
require "thread"
require "benchmark"

require "bunny/concurrent/synchronized_sorted_set"

puts
puts "-" * 80
puts "Benchmarking on #{RUBY_DESCRIPTION}"

n  = 2_000_000
s  = SortedSet.new

# warm up the JIT, etc
puts "Doing a warmup run..."
n.times do |i|
  s << 1
  s << i
  s.delete i
  s << i
end

t1  = Benchmark.realtime do
  n.times do |i|
    s << 1
    s << i
    s.delete i
    s << i
    s.length
  end
end
r1  = (n.to_f/t1.to_f)

s2 = SynchronizedSortedSet.new
t2  = Benchmark.realtime do
  n.times do |i|
    s2 << 1
    s2 << i
    s2.delete i
    s2 << i
    s2.length
  end
end
r2  = (n.to_f/t2.to_f)

puts "Mixed sorted set ops, rate: #{(r1 / 1000).round(2)} KGHz"
puts "Mixed synchronized sorted set ops, rate: #{(r2 / 1000).round(2)} KGHz"
puts
puts "-" * 80