Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Laravel enterprise level code quality

Name: Anonymous 2014-06-01 1:30

Laravel enterprise level code quality


public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();

switch (count($args))
{
case 0:
return $instance->$method();

case 1:
return $instance->$method($args[0]);

case 2:
return $instance->$method($args[0], $args[1]);

case 3:
return $instance->$method($args[0], $args[1], $args[2]);

case 4:
return $instance->$method($args[0], $args[1], $args[2], $args[3]);

default:
return call_user_func_array(array($instance, $method), $args);
}
}

Name: sage 2014-06-01 1:49

Name: Anonymous 2014-06-01 3:05

I don't understand why not just do:

return call_user_func_array(array($instance, $method), $args);


The rest of the code seems unnecessary.

Name: Anonymous 2014-06-01 3:30

>>3
It's probably an optimization. Rather than creating arrays and passing arrays around as parameters and also having extra function call overhead with call_user_func_array, it just calls the method directly for small argument counts.

Name: Anonymous 2014-06-01 4:25

what language is this?

Name: Anonymous 2014-06-01 4:41

>>4
Here is a benchmark to prove my case:


<?php

class Bar {

public function addNumbers($a, $b)
{
return $a + $b;
}

}

class Foo {

private static $rootInstance;

protected static function getFacadeRoot()
{
if(is_null(self::$rootInstance))
self::$rootInstance = new Bar;

return self::$rootInstance;
}

}

class Unoptimized extends Foo {

public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
return call_user_func_array(array($instance, $method), $args);
}

}

class Optimized extends Foo {

public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();

switch (count($args))
{
case 0:
return $instance->$method();

case 1:
return $instance->$method($args[0]);

case 2:
return $instance->$method($args[0], $args[1]);

case 3:
return $instance->$method($args[0], $args[1], $args[2]);

case 4:
return $instance->$method($args[0], $args[1], $args[2], $args[3]);

default:
return call_user_func_array(array($instance, $method), $args);
}
}

}

// instantiate the instance with a static call to make sure the comparison is fair
Optimized::addNumbers(1, 2);

$c = 1000000;
$t = microtime(true);

for($i = 0; $i < $c; ++$i)
Unoptimized::addNumbers(1, 2);

$t = microtime(true) - $t;
echo 'Unoptimized: ' . $t . PHP_EOL;
$t = microtime(true);

for($i = 0; $i < $c; ++$i)
Optimized::addNumbers(1, 2);

$t = microtime(true) - $t;
echo 'Optimized: ' . $t . PHP_EOL;


Output:
Unoptimized: 2.942752122879
Optimized: 2.2685830593109

Name: Anonymous 2014-06-01 5:21

>>6


$c = 1000000;


see how optimized this code is?

IHBT

Name: Anonymous 2014-06-01 5:23

>>7
WHYBT?

Name: Anonymous 2014-06-01 5:26

>>8

2.942752122879 - 2.2685830593109 = 0.6741690635681

that's for 1000000 iterations. so for a single iteration, you have optimized for a whooping 0.000000674169064

ENTERPRISE LEVEL OPTIMIZATION

Name: Anonymous 2014-06-01 5:37

>>9
My optimizations don't whoop, friend.

I don't think several hundred or even a thousand facade calls per request is a stretch of the imagination. And if you are receiving 1,000 requests per second then it easily adds up.

Name: Anonymous 2014-06-01 5:39

>>10

really? if your php code is hardly the bottleneck.

several hundred or even a thousand facade calls per request

that's top notch faggotry right there, gents.

Name: Anonymous 2014-06-01 5:41

>>11
that's top notch faggotry right there, gents.
That post was back to /g/ quality!

Name: Anonymous 2014-06-01 13:51

if your php code is hardly the bottleneck.
then?

Don't change these.
Name: Email:
Entire Thread Thread List