
class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .
class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .class Test_1 { public function _myFn($mv){ $_rand = rand(0, 99999999); $_arr = get_defined_functions(); return sha1($_rand . $mv . implode( ',' , $_arr[ 'internal' ])); } } $i = 0; $max = 10000; $_st = microtime( true ); $test = new Test_1(); while ($i < $max) { $test->_myFn($i); $i++; } $_ft = microtime( true ); echo "\n Total: " . round(($_ft - $_st), 6) . " sec; \n" ; echo "Per call: " . round((($_ft - $_st)/$max), 6) . " sec \n" ; /* * Total: 28.779473 sec; * Per call: 0.002878 sec */ * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- / *
 - * Total: 28.914997 sec;
 - * Per call: 0.002891 sec
 - * /
 
* This source code was highlighted with Source Code Highlighter .
- / *
 - * Total: 32.493496 sec;
 - * Per call: 0.00065 sec
 - * /
 
* This source code was highlighted with Source Code Highlighter .
- / *
 - * Proxy class and test code
 - * /
 - class HotCode
 - {
 - protected $ _current_v = null ; // current code version
 - protected $ _current_timestamp = 0; // timestamp of the function that is executed
 - protected $ _current_fn = null ; // name of the current function
 - public function __call ($ fnmame, $ fparam)
 - {
 - if (($ this -> _ current_fn! = null ) && ($ this -> _ current_timestamp! = null ))
 - {
 - echo $ this -> _ current_fn. "from" . date ( 'jmY H: i s' , $ this -> _ current_timestamp). "is current function \ n" ;
 - }
 - clearstatcache ();
 - // check, can there be current code?
 - $ _file_last = filemtime ( '/var/www/deamon/hot_swap_fn.php' );
 - if ($ _file_last === FALSE)
 - {
 - // what = something wrong
 - throw new Exception ( 'Including file does not exist' );
 - }
 - echo "Last modif of file:" . date ( 'jmY H: i s' , $ _file_last). "\ n" ;
 - echo "Now:" . date ( 'jmY H: i s' , time ()). "\ n" ;
 - if (($ this -> _ current_v == null ) || ((is_integer ($ _ file_last))) && ($ _file_last> $ this -> _ current_timestamp)))
 - {
 - // forcefully connect
 - $ _xfn = require ( 'hot_swap_fn.php' );
 - // we got an array of functions defined there, their versions and aliases
 - if (array_key_exists ($ fnmame, $ _xfn))
 - {
 - // method is
 - if ($ this -> _ current_v == null )
 - {
 - // first time, yeah
 - $ this -> _ current_v = $ _xfn [$ fnmame] [ 'v' ]; // remember the version
 - $ this -> _ current_fn = $ _xfn [$ fnmame] [ 'fn' ];
 - $ this -> _ current_timestamp = $ _file_last;
 - }
 - else
 - {
 - // compare versions
 - if ($ _xfn [$ fnmame] [ 'v' ]> $ this -> _ current_v)
 - {
 - // newer version
 - $ this -> _ current_v = $ _xfn [$ fnmame] [ 'v' ]; // remember the version
 - $ this -> _ current_fn = $ _xfn [$ fnmame] [ 'fn' ];
 - $ this -> _ current_timestamp = $ _file_last;
 - }
 - // otherwise I use the old one
 - }
 - // Call with parameters
 - if ($ this -> _ current_fn! = null )
 - return call_user_func ($ this -> _ current_fn, $ fparam [0]);
 - else
 - return $ this -> defaultEmptyFnCall ($ fparam); // otherwise default "stub"
 - }
 - else
 - return $ this -> defaultEmptyFnCall ($ fparam);
 - }
 - else
 - if ($ this -> _ current_fn! = null )
 - return call_user_func ($ this -> _ current_fn, $ fparam [0]);
 - else
 - return $ this -> defaultEmptyFnCall ($ fparam); // otherwise default "stub"
 - }
 - // call if requested a function that does not exist
 - private function defaultEmptyFnCall ($ param = null )
 - {
 - var_dump ($ param);
 - }
 - }
 - $ _my_hot_class = new HotCode ();
 - <? php
 - / * File: hot_swap_fn.php
 - * Plugin file with function for Hot swap
 - * /
 - function _myFn_2 ($ param)
 - {
 - $ _rand = rand (0, 99999999);
 - $ _arr = get_defined_functions ();
 - return sha1 ($ _ rand. $ param. implode ( ',' , $ _arr [ 'internal' ]));
 - }
 - return array (
 - '_myFn' => array ( 'v' => 2,
 - 'fn' => '_myFn_2' )
 - );
 - ?>
 
Source: https://habr.com/ru/post/81783/
All Articles