Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:ruby-amqp/amq-protocol

  • Loading branch information...
commit 9d7fd9d184c53ca1765a8ea6c791a82883943d48 2 parents cc5883f + 0c6dfc1
@michaelklishin michaelklishin authored
View
3  .gitignore
@@ -3,6 +3,8 @@
/.ruby-version
tmp
*.pyc
+*.iml
+.idea
/vendor/bundle
/vendor/amq-*
/coverage
@@ -13,3 +15,4 @@ Gemfile.lock
bin/*
*.bundle
Makefile
+profiling/dumps/*
View
4 README.md
@@ -56,3 +56,7 @@ Any questions you may have should be sent to the [Ruby AMQP mailing list](http:/
## License
MIT (see LICENSE in the repository root).
+
+
+[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ruby-amqp/amq-protocol/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
+
View
7 lib/amq/pack.rb
@@ -7,7 +7,8 @@ module AMQ
# compatible with Ruby 1.8+.
module Pack
UINT64 = "Q".freeze
- INT16 = "c".freeze
+ UINT16_BE = "n".freeze
+ INT16 = "c".freeze
if Endianness.big_endian?
def self.pack_uint64_big_endian(long_long)
@@ -42,8 +43,8 @@ def self.pack_int16_big_endian(short)
end
def self.unpack_int16_big_endian(data)
- data = data.bytes.to_a.reverse.map(&:chr).join
- data.unpack(INT16)
+ value = data.bytes.to_a.map(&:chr).join.unpack(UINT16_BE)[0]
+ [(value & ~(1 << 15)) - (value & (1 << 15))]
end
end
end
View
9 profiling/README.md
@@ -0,0 +1,9 @@
+# Profiling Scripts
+
+This directory contains profiling scripts. Currently they use [stackprof](https://github.com/tmm1/stackprof) which
+requires Ruby 2.1+ (preview2 or later).
+
+## Running the Profiler
+
+ ruby profiling/stackprof/body_framing_with_2k_payload.rb
+ stackprof profiling/dumps/body_framing_with_2k_payload.dump --text
View
9 profiling/pure/body_framing_with_2k_payload.rb → profiling/stackprof/body_framing_with_2k_payload.rb
@@ -17,16 +17,17 @@
puts "Doing a warmup run..."
15_000.times { AMQ::Protocol::Method.encode_body("ab" * 1024, 1, FRAME_SIZE) }
-require 'ruby-prof'
+require 'stackprof'
# preallocate
ary = Array.new(n) { "ab" * 1024 }
puts "Doing main run..."
-result = RubyProf.profile do
+result = StackProf.run(mode: :wall) do
n.times { |i| AMQ::Protocol::Method.encode_body(ary[i], 1, FRAME_SIZE) }
end
-printer = RubyProf::FlatPrinter.new(result)
-printer.print(STDOUT, {})
+File.open('./profiling/dumps/body_framing_with_2k_payload.dump', "w+") do |f|
+ f.write Marshal.dump(result)
+end
View
18 spec/amq/hacks_spec.rb → spec/amq/pack_spec.rb
@@ -4,7 +4,23 @@
module AMQ
- describe Hacks do
+ describe Pack do
+ context "16-bit big-endian packing / unpacking" do
+ let(:examples_16bit) {
+ {
+ 0x068D => "\x06\x8D" # 1677
+ }
+ }
+
+ it "unpacks signed integers from a string to a number" do
+ examples_16bit.each do |key, value|
+ described_class.unpack_int16_big_endian(value)[0].should == key
+ end
+ end
+ end
+
+
+
context "64-bit big-endian packing / unpacking" do
let(:examples) {
{
Please sign in to comment.
Something went wrong with that request. Please try again.