How to speed up the decoding of the string in binary format in PHP?

Good day!

API the server the document comes in the form of coded strings. The line has a number of groups of digits in 3 pieces, corresponding to 1 byte. This nonsense no one will not change.

59db61ab9514b173799695.png

The existing code on the local machine with i5 3rd generation and enabled XDebug works fine as slowly. Decodes the document in about 5-6 minutes (!!!).

public function DecodePolicy($Value)
{
 $length = strlen( $Value );

 $triple_char = ";
 $triple_char_length = 0;

 $buffer = ";

 for ($i = 0; $i < $length; $i++)
{
 if ( $triple_char_length == 3 )
{
 $byte = intval( $triple_char );

 $buffer = $buffer . chr( $byte );

 $triple_char = ";
 $triple_char_length = 0;
}

 $char = $Value[$i];

 $triple_char = $triple_char . $char;
$triple_char_length++;
}

 return $buffer;
 }


How is it possible to optimize? And is it possible to optimize at all?
June 14th 19 at 18:22
3 answers
June 14th 19 at 18:24
Solution
immediately to split the input to 3 digits in one of tons of methods.
And shorten the cycle 3 times immediately.

Well and further to look at along the way.
Thank you very much! Only gave acceleration in 7 times! This is more than enough! - neva29 commented on June 14th 19 at 18:27
June 14th 19 at 18:26
Here is the fit?
Possible! Is it possible to ask for example for my case? - neva29 commented on June 14th 19 at 18:29
The link is full of examples. For your nedam because I write in Go and PHP are not at hand - neva29 commented on June 14th 19 at 18:32
June 14th 19 at 18:28
For starters, disable xdebug, it is suspected that your code will be accelerated 3-4 times (in my life there was a case, when acceleration occurred from 11 minutes to 30 seconds, however in our tests).
Nonsense - neva29 commented on June 14th 19 at 18:31
Nonsense - neva29 commented on June 14th 19 at 18:34

Find more questions by tags PHP