This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bin/perf.php | |
php bin/perf.php | |
time: 0.016928ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo | |
time: 0.031948ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo.bar | |
time: 0.046968ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo.bar.baz | |
time: 0.060797ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo.bar.baz.bad | |
time: 0.145912ms, description: ./bin/../tests/compliance/perf/deep_hierarchy.json, name: j49.j48.j47.j46.j45.j44.j43.j42.j41.j40 | |
time: 0.711918ms, description: ./bin/../tests/compliance/perf/deep_hierarchy.json, name: j49.j48.j47.j46.j45.j44.j43.j42.j41.j40.j39.j38.j37.j36.j35.j34.j33.j32.j31.j30.j29.j28.j27.j26.j25.j24.j23.j22.j21.j20.j19.j18.j17.j16.j15.j14.j13.j12.j11.j10.j9.j8.j7.j6.j5.j4.j3.j2.j1.j0 | |
time: 0.090837ms, description: ./bin/../tests/compliance/perf/multiwildcard.json, name: foo[*].bar[*].kind | |
time: 0.091791ms, description: ./bin/../tests/compliance/perf/multiwildcard.json, name: foo[*].bar[0].kind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
@$i = $argv[1] ?: 1000; | |
$c = array(); | |
$s = microtime(true); | |
for ($j = 0; $j < $i; $j++) { | |
if ($c) {} | |
} | |
echo 'Empty Array: ' . (microtime(true) - $s) . "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require("http"); | |
http.createServer(function(req, res) { | |
req.addListener("data", function(chunk) { | |
// Read data chunks | |
}); | |
// Called when the request completes | |
req.addListener("end", function() { | |
res.writeHead(200, "OK", { "Content-Length": 10 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$m = curl_multi_init(); | |
function sendMulti($ch) | |
{ | |
global $m; | |
curl_multi_add_handle($m, $ch); | |
$active = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Various methods of computing Fibonacci numbers in PHP | |
*/ | |
class Fibonacci | |
{ | |
/** | |
* @var array Memoization cache | |
* @see Fibonacci::memoized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fibMemo = call_user_func(function () { | |
$memo = array(0 => 0, 1 => 1); | |
$fib = function ($n) use (&$memo, &$fib) { | |
if (!isset($memo[$n])) { | |
$memo[$n] = $fib($n - 1) + $fib($n - 2); | |
} | |
return $memo[$n]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function evalXml2Array(SimpleXMLElement $xml) | |
{ | |
eval('$x = ' . str_replace(array('SimpleXMLElement::__set_state(', '))'), array('', ')'), var_export($xml, true)) . ';'); | |
return $x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Note that this will not maintain XML attributes | |
function jsonXml2Array(SimpleXMLElement $xml) | |
{ | |
return json_decode(json_encode($xml), true); | |
} | |
function jsonXml2ArrayWithNamespacedAttributes($xml) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function xml2array($xml) | |
{ | |
$arr = array(); | |
foreach ($xml->getNamespaces() + array(null) as $prefix => $namespace) { | |
foreach ($xml->attributes($namespace) as $key => $value) { | |
// Add prefixes to prefixed attributes | |
if (is_string($prefix)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function iXml2array($xml) | |
{ | |
$result = array(); | |
$stack = array(array(&$result, &$xml)); | |
do { | |
$frame = array_pop($stack); |