On Tue, Jul 17, 2018 at 1:18 PM Dan Ackroyd <dan...@basereality.com> wrote:

> On 15 July 2018 at 20:39, Zeljko Mitic <mitke...@gmail.com> wrote:
> > PHP is dynamic language and each typed typehinted parameter has to be
> > checked every time.
>
> If you think your code would benefit appreciably from having parameter
> types removed, I would strongly recommend looking at
> https://preprocess.io/ and similar libraries.
>
> Preprocessing is used in Javascript to quite radically change what is
> possible to code in 'Javascript' and has allowed rapid development in
> how 'Javascript' can be used. For example JSX is something that would
> never have been approved by the ECMA committee.....but because it was
> implemented a preprocessing step it never needed to be approved before
> could get wide-scale usage.
>
> cheers
> Dan
> Ack
>

It won't help, preprocess.io doesn't remove typehints.  But this is mostly
intended for other features like generics/typed arrays for which I have
read that speed is a big blocker.

Anyway, if anyone is interested, I did some testing on parameter check. The
code:
---
class Customer {}

function test(Customer $customer) {}

$customer = new Customer();
$start = microtime(true);

for ($i=1;$i<100000000;$i++) {  // 100 million
    test($customer);
}

echo microtime(true) - $start;
---

Tested 3 times, average time: 3.58s

When I removed typehint from test() function, average time was: 2.76s

Difference is 29.7%

I know it is unrealistic scenario because there is nothing else in the
code, I was just curios.

Reply via email to