Příručka stylu psaní: Porovnání verzí
Z Freenetis Wiki
(Založena nová stránka: Pro inspiraci: *http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml *http://www.kernel.org/doc/Documentation/CodingStyle *http://en.wikipedia.org/wiki/Indent_sty...) |
m (Quimi přesunul stránku PÅ™ÃruÄka stylu psanà na Příručka stylu psaní bez založení přesměrování) |
||
| (Není zobrazeno 5 mezilehlých verzí od 2 dalších uživatelů.) | |||
| Řádek 1: | Řádek 1: | ||
| + | [[en:Coding Style Guide]] | ||
Pro inspiraci: | Pro inspiraci: | ||
*http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml | *http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml | ||
| Řádek 5: | Řádek 6: | ||
==Static vs. normal methods/members/variables== | ==Static vs. normal methods/members/variables== | ||
| − | In PHP, static is slower (see http://stackoverflow.com/questions/1472721/php-performance-of-static-methods-vs-functions). | + | |
| + | *Static class members require longer syntax when used | ||
| + | *In PHP, static is slower (see http://stackoverflow.com/questions/1472721/php-performance-of-static-methods-vs-functions). | ||
Try this example: | Try this example: | ||
| + | <?php | ||
| + | class Normal { | ||
| + | public $x=0; | ||
| + | } | ||
| + | |||
| + | class Statik { | ||
| + | public static $x=0; | ||
| + | } | ||
| + | |||
| + | $limit=50000; | ||
| + | $mem1=memory_get_usage(); | ||
| + | $time1=microtime(true); | ||
| + | $normal=new Normal(); | ||
| + | echo "Normal object test:<br/>"; | ||
| + | |||
| + | for ($i=0; $i<$limit; $i++) { | ||
| + | $normal->x=$normal->x+$i; | ||
| + | |||
| + | } | ||
| + | echo $normal->x."<br/>"; | ||
| + | |||
| + | $mem2=memory_get_usage(); | ||
| + | $time2=microtime(true); | ||
| + | |||
| + | echo "Static object test:<br/>"; | ||
| + | |||
| + | for ($i=0; $i<$limit; $i++) { | ||
| + | Statik::$x=Statik::$x+$i; | ||
| + | } | ||
| + | |||
| + | echo Statik::$x."<br/>"; | ||
| + | |||
| + | $mem3=memory_get_usage(); | ||
| + | $time3=microtime(true); | ||
| + | |||
| + | printf("Normal: Memory=%d time=%f<br/>", $mem2-$mem1, $time2-$time1); | ||
| + | printf("Static: Memory=%d time=%f<br/>", $mem3-$mem2, $time3-$time2); | ||
| + | ?> | ||
| − | + | Result | |
| − | + | Normal: Memory=728 time=0.049930 | |
| − | + | Static: Memory=220 time=0.057258 | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Aktuální verze z 31. 1. 2018, 14:16
Pro inspiraci:
- http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
- http://www.kernel.org/doc/Documentation/CodingStyle
- http://en.wikipedia.org/wiki/Indent_style#K.26R_style]
Static vs. normal methods/members/variables
- Static class members require longer syntax when used
- In PHP, static is slower (see http://stackoverflow.com/questions/1472721/php-performance-of-static-methods-vs-functions).
Try this example:
<?php
class Normal {
public $x=0;
}
class Statik {
public static $x=0;
}
$limit=50000;
$mem1=memory_get_usage();
$time1=microtime(true);
$normal=new Normal();
echo "Normal object test:
";
for ($i=0; $i<$limit; $i++) {
$normal->x=$normal->x+$i;
}
echo $normal->x."
";
$mem2=memory_get_usage();
$time2=microtime(true);
echo "Static object test:
";
for ($i=0; $i<$limit; $i++) {
Statik::$x=Statik::$x+$i;
}
echo Statik::$x."
";
$mem3=memory_get_usage();
$time3=microtime(true);
printf("Normal: Memory=%d time=%f
", $mem2-$mem1, $time2-$time1);
printf("Static: Memory=%d time=%f
", $mem3-$mem2, $time3-$time2);
?>
Result
Normal: Memory=728 time=0.049930 Static: Memory=220 time=0.057258