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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/usr/bin/env ruby
# encoding: utf-8
# frozen_string_literal: true
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
require "amq/protocol/client"
require "benchmark/ips"
puts
puts "-" * 80
puts "Frame Encoding Benchmarks on #{RUBY_DESCRIPTION}"
puts "-" * 80
# Test data
SMALL_PAYLOAD = "x" * 100
MEDIUM_PAYLOAD = "x" * 1024
LARGE_PAYLOAD = "x" * 16384
CHANNEL = 1
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
x.report("Frame.encode(:method, small)") do
AMQ::Protocol::Frame.encode(:method, SMALL_PAYLOAD, CHANNEL)
end
x.report("Frame.encode(:method, medium)") do
AMQ::Protocol::Frame.encode(:method, MEDIUM_PAYLOAD, CHANNEL)
end
x.report("Frame.encode(:body, large)") do
AMQ::Protocol::Frame.encode(:body, LARGE_PAYLOAD, CHANNEL)
end
x.report("MethodFrame.new + encode") do
frame = AMQ::Protocol::MethodFrame.new(SMALL_PAYLOAD, CHANNEL)
frame.encode
end
x.report("BodyFrame.new + encode") do
frame = AMQ::Protocol::BodyFrame.new(MEDIUM_PAYLOAD, CHANNEL)
frame.encode
end
x.report("HeartbeatFrame.encode") do
AMQ::Protocol::HeartbeatFrame.encode
end
x.compare!
end
puts
puts "-" * 80
puts "Frame Header Decoding"
puts "-" * 80
# Encoded frame headers
METHOD_HEADER = [1, 0, 1, 0, 0, 0, 100].pack("CnN") # type=1, channel=1, size=100
BODY_HEADER = [3, 0, 5, 0, 0, 16, 0].pack("CnN") # type=3, channel=5, size=4096
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
x.report("Frame.decode_header (method)") do
AMQ::Protocol::Frame.decode_header(METHOD_HEADER)
end
x.report("Frame.decode_header (body)") do
AMQ::Protocol::Frame.decode_header(BODY_HEADER)
end
x.compare!
end
|