Permalink
Browse files

Revert "Performance optimization"

This reverts commit 4e012ba.
  • Loading branch information...
1 parent 4e012ba commit 393689f37657af18b0304d5668a5a338c1afda94 José Micó committed Apr 13, 2012
Showing with 8 additions and 15 deletions.
  1. +2 −2 eg/bench.pl
  2. +2 −6 lib/Net/AMQP/Frame/Header.pm
  3. +4 −7 lib/Net/AMQP/Frame/Method.pm
View
@@ -70,8 +70,8 @@ sub deserialize {
# On my old mobile Core Duo 1.66 Ghz, I got:
#
# Benchmark: timing 5000 iterations of deserialize, serialize ...
-# deserialize: 2 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 4672.90/s (n=5000)
-# serialize : 1 wallclock secs ( 1.12 usr + 0.00 sys = 1.12 CPU) @ 4464.29/s (n=5000)
+# deserialize: 1 wallclock secs ( 1.19 usr + 0.00 sys = 1.19 CPU) @ 4201.68/s (n=5000)
+# serialize : 2 wallclock secs ( 1.27 usr + 0.00 sys = 1.27 CPU) @ 3937.01/s (n=5000)
my $raw_frames = serialize();
@@ -93,9 +93,7 @@ sub parse_payload {
my %header_frame;
my $arguments = $header_class->frame_arguments;
- my $args_count = scalar @$arguments;
-
- for (my $i = 0; $i < $args_count; $i += 2) {
+ for (my $i = 0; $i <= $#{ $arguments }; $i += 2) {
my ($key, $type) = ($arguments->[$i], $arguments->[$i + 1]);
my $is_set = shift @fields_set;
next unless $is_set;
@@ -127,9 +125,7 @@ sub to_raw_payload {
my (@values, @fields_set);
my $arguments = $header_frame->frame_arguments;
- my $args_count = scalar @$arguments;
-
- for (my $i = 0; $i < $args_count; $i += 2) {
+ for (my $i = 0; $i <= $#{ $arguments }; $i += 2) {
my ($key, $type) = ($arguments->[$i], $arguments->[$i + 1]);
if (! defined $header_frame->{$key}) {
@@ -84,10 +84,9 @@ sub parse_payload {
}
my $arguments = $method_class->frame_arguments;
- my $args_count = scalar @$arguments;
my %method_frame;
- for (my $i = 0; $i < $args_count; $i += 2) {
+ for (my $i = 0; $i <= $#{ $arguments }; $i += 2) {
my ($key, $type) = ($arguments->[$i], $arguments->[$i + 1]);
my $value;
@@ -96,7 +95,7 @@ sub parse_payload {
my @bit_keys = ($key);
# Group all following bits together into octets, up to 8
- while (($i + 3) < $args_count && $arguments->[$i + 3] eq 'bit') {
+ while (($i + 3) <= $#{ $arguments } && $arguments->[$i + 3] eq 'bit') {
$i += 2;
push @bit_keys, $arguments->[$i];
last if int @bit_keys == 8;
@@ -137,17 +136,15 @@ sub to_raw_payload {
$response_payload .= pack_short_integer($self->method_id);
my $arguments = $method_frame->frame_arguments;
- my $args_count = scalar @$arguments;
-
- for (my $i = 0; $i < $args_count; $i += 2) {
+ for (my $i = 0; $i <= $#{ $arguments }; $i += 2) {
my ($key, $type) = ($arguments->[$i], $arguments->[$i + 1]);
my $value;
if ($type eq 'bit') {
# Group all following bits together into octets, up to 8
my @bits = ($method_frame->{$key});
- while (($i + 3) < $args_count && $arguments->[$i + 3] eq 'bit') {
+ while (($i + 3) <= $#{ $arguments } && $arguments->[$i + 3] eq 'bit') {
$i += 2;
push @bits, $method_frame->{ $arguments->[$i] };
last if int @bits == 8;

0 comments on commit 393689f

Please sign in to comment.