[asterisk-users] Benchmarking AGI performance in C, PHP, and Perl

Steve Edwards asterisk.org at sedwards.com
Tue Jul 12 20:46:04 CDT 2011


> On Mon, Jul 11, 2011 at 06:45:08PM -0700, Steve Edwards wrote:

>> while read line; do
>>    epoch=`echo $line | cut -d '|' -f 1`
>>    if [ $epoch -ge $start_epoch -a $epoch -le $end_epoch ]; then
>>      echo $line
>>    fi
>> done < /var/log/asterisk/queue_log

[snipping snippy comments about improving the second line]

>>         epoch=${line:0:10}
>>
>> Since the Epoch will be 10 digits for the next 300 years, I'd feel
>> relatively comfortable with this solution.

On Wed, 13 Jul 2011, Tzafrir Cohen wrote:

> For the record, I suspect you meant:
>
>  epoch=${line%%|*}

I didn't mean it, but I like it. Thanks.

> Actually, that mistake is easy to make in shell scripts. But even simple
> script languages such as awk fare much better here:
>
> awk -F'|' "{
> 	epoch=\$1;
> 	if (epoch <= $start_epoch && epoch >= $end_epoch) {
> 		print epoch
> 	}
> }" /var/log/asterisk/queue_log

1) The 2 conditionals should be swapped.

2) I think you meant 'print \$0' instead of 'print epoch'

We'll leave defining start_epoch and end_epoch as an exercise for the 
reader :)

> How much time will it take you to write something as fast as this in C?

Well, the C version was still 10 times faster, but I concede it took a 
whole lot longer to write.

The question always comes down to how many times are you going to use it 
and how much will it cost to make it faster.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list