videlalvaro/php-amqplib — pull request #113 by geoffroy-aubry (2013-10-04 09:23:11+00:00)
Title: Optimization

Hi, while reviewing performance I found three methods to optimize with buffers:
* `AbstractConnection::prepare_content()`
* `AMQPChannel::basic_publish()`
* `AMQPChannel::publish_batch()`

#### Benchmark configuration
* on my laptop,
* with series of 50k `basic_publish()` and 50k `batch_basic_publish()` with `publish_batch()` every 100
* 1 queue non durable
* 1 exchange non durable
* purge queue between each measure

#### Result

With 50k `basic_publish()` (time in s):

Origin With optimized With previous opt.
AbstractConnection::prepare_content()	plus AMQPChannel::pre_publish()
11,44	10,25	6,64
10,40	10,23	6,80
10,55	10,36	6,55
11,18	6,84
10,21	6,74

Avg 10,76	10,28	6,71
Gain	4,43%	34,69%

With 50k `batch_basic_publish()` and `publish_batch()` every 100 (time in s):

Origin With optimized With previous opt.
AbstractConnection::prepare_content()	plus AMQPChannel::pre_publish()
9,14	8,35	5,30
9,49	8,86	5,33
9,56	8,78	5,22
9,04	8,70	5,38
9,25	8,59	5,28

Avg 9,30	8,66	5,30
Gain	6,88%	38,75%

#### Tests
* `make test` OK
* `make benchmark` OK