Created
March 8, 2011 13:06
-
-
Save iconara/860245 to your computer and use it in GitHub Desktop.
The benchmark results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Result of running bm.rb four times (which runs 100K iterations of encode or decode | |
over a set of values), taking the "user" column from the results: | |
+------------------+--------+---------+---------+---------+---------+ | |
| | Method | 1st run | 2nd run | 3rd run | 4th run | | |
+------------------+--------+---------+---------+---------+---------+ | |
| Baseline | Decode | 1.92 | 1.92 | 1.94 | 2.22 | | |
| | Encode | 1.90 | 1.91 | 1.91 | 1.92 | | |
+------------------+--------+---------+---------+---------+---------+ | |
| Constant Strings | Decode | 2.07 | 1.81 | 1.82 | 1.84 | | |
| | Encode | 2.14 | 1.71 | 1.77 | 1.79 | | |
+------------------+--------+---------+---------+---------+---------+ | |
| Pack Cache | Decode | 2.15 | 2.10 | 2.01 | 2.03 | | |
| | Encode | 2.00 | 2.05 | 1.86 | 1.86 | | |
+------------------+--------+---------+---------+---------+---------+ | |
Using the pack cache patch is in almost all cases slower than using literal strings, | |
whereas constant strings is considerably faster. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$: << 'lib' | |
require 'benchmark' | |
require 'bigdecimal' | |
require 'amq/protocol/table' | |
# this sample data was taken from the specs, removed the BigDecimal examples | |
# since they skewed the test results (one of the patches optimized for that too) | |
timestamp = Time.utc(2010, 12, 31, 23, 58, 59) | |
data = { | |
Hash.new => "\x00\x00\x00\x00", | |
{"test" => 1} => "\x00\x00\x00\n\x04testI\x00\x00\x00\x01", | |
{"test" => "string"} => "\x00\x00\x00\x10\x04testS\x00\x00\x00\x06string", | |
{"test" => Hash.new} => "\x00\x00\x00\n\x04testF\x00\x00\x00\x00", | |
{"test" => timestamp} => "\x00\x00\x00\x0e\x04testT\x00\x00\x00\x00M\x1enC" | |
} | |
iterations = 100_000 | |
Benchmark.bmbm do |bm| | |
bm.report('Decode') do | |
iterations.times do | |
data.each do |key, value| | |
AMQ::Protocol::Table.decode(value) | |
end | |
end | |
end | |
bm.report('Encode') do | |
iterations.times do | |
data.each do |key, value| | |
AMQ::Protocol::Table.encode(key) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# runs the benchmarks on the three relevant commits | |
baseline='cdd01bc3779b9e2e414275ccfb79823cd8823593' | |
constant_strings='b95225cf763b7242c808ad47889dd2ab3bf35a97' | |
pack_cache='b6d8133e55a65de16c0c44662c0e4ad90874747c' | |
echo 'BASELINE' | |
git co $baseline | |
ruby bm.rb | |
echo | |
echo 'CONSTANT STRINGS' | |
git co $constant_strings | |
ruby bm.rb | |
echo | |
echo 'PACK CACHE' | |
git co $pack_cache | |
ruby bm.rb | |
echo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BASELINE | |
Previous HEAD position was b6d8133... Changed from constants using PACK_CACHE | |
HEAD is now at cdd01bc... These are identical. | |
Rehearsal ------------------------------------------ | |
Decode 1.950000 0.010000 1.960000 ( 1.960757) | |
Encode 1.950000 0.000000 1.950000 ( 1.953454) | |
--------------------------------- total: 3.910000sec | |
user system total real | |
Decode 2.220000 0.010000 2.230000 ( 2.264727) | |
Encode 1.920000 0.000000 1.920000 ( 1.912063) | |
CONSTANT STRINGS | |
Previous HEAD position was cdd01bc... These are identical. | |
HEAD is now at b95225c... Replaced literal strings with constants | |
Rehearsal ------------------------------------------ | |
Decode 1.830000 0.000000 1.830000 ( 1.828105) | |
Encode 1.760000 0.010000 1.770000 ( 1.759748) | |
--------------------------------- total: 3.600000sec | |
user system total real | |
Decode 1.840000 0.000000 1.840000 ( 1.845521) | |
Encode 1.790000 0.000000 1.790000 ( 1.789752) | |
PACK CACHE | |
Previous HEAD position was b95225c... Replaced literal strings with constants | |
HEAD is now at b6d8133... Changed from constants using PACK_CACHE | |
Rehearsal ------------------------------------------ | |
Decode 2.300000 0.010000 2.310000 ( 2.375506) | |
Encode 1.880000 0.010000 1.890000 ( 1.883791) | |
--------------------------------- total: 4.200000sec | |
user system total real | |
Decode 2.030000 0.000000 2.030000 ( 2.034270) | |
Encode 1.860000 0.010000 1.870000 ( 1.868044) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment