3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace wrossmann\merkle; class Node { public $value = NULL; public $isLeaf = false; public $height = 0; public $left = NULL; public $right = NULL; public $parent = NULL; } class Tree { protected $root = null; protected $nodes = []; public function serialize() { yield from $this->serializeGenerator($this->root); } // Serialize based on a depth-first traversal protected function serializeGenerator(Node $node) { yield [ 'v' => $node->value, 'l' => $node->isLeaf ]; if( ! is_null($node->left) ) { yield from $this->serializeGenerator($node->left); } if( ! is_null($node->right) ) { yield from $this->serializeGenerator($node->right); } } } // pre-constructed tree $m = unserialize(gzuncompress(base64_decode('eJy1VbtuwzAMzLdw7GTLz1K/UDhLxyxKIj9Qxy6kPoYg/17SXmIoKBBI2kj6rDvyaHmPIkX4NbO1FzVNh4s2H6M+vButAQVeLVYIu5edmecvkPvH6GY+E7pkdIHwo8ZvDdJijaCOp7Nuu57TEmGwb1q1II+YrIVeD11PBw9LIUcYdfs0T77yROUQzBGVgaDKIUj/JWjkcoRZHzYr9lMZPVFqME3k7R7wtB634QB6NqXSRyF5Etl1gp7CzkC8enriNhxAj+vJFuSjmZREvwEEc8TeBB128kXmuQluwwH0bEq517KSKZFtJ2gXdgiV16oT1G04gJ4Hprjf512l4bxe/tsTKbUgFaVXpqZbOCcNKb+VUiAoyDIKMj46oSDnXagoKPguYHDJQkoKKgpqWpPbH0CgjUU='))); // only outputs the final element printf("%s\n\n", json_encode(iterator_to_array($m->serialize()))); // produces all elemenst as expected foreach($m->serialize() as $item) { printf("%s\n", json_encode($item)); }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.70.0120.00316.88
8.3.60.0130.00618.68
8.3.50.0120.00617.99
8.3.40.0080.00818.72
8.3.30.0070.00718.84
8.3.20.0050.00319.15
8.3.10.0000.00723.64
8.3.00.0040.00420.71
8.2.190.0090.00616.63
8.2.180.0090.01225.92
8.2.170.0070.00722.96
8.2.160.0130.00322.11
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0000.00826.16
8.2.120.0000.00721.07
8.2.110.0100.00020.64
8.2.100.0070.00718.03
8.2.90.0060.00317.75
8.2.80.0030.00618.80
8.2.70.0000.00817.88
8.2.60.0090.00017.63
8.2.50.0030.00517.72
8.2.40.0090.00019.35
8.2.30.0080.00019.29
8.2.20.0000.00718.15
8.2.10.0000.00718.23
8.2.00.0000.00818.25
8.1.280.0070.00725.92
8.1.270.0080.00022.27
8.1.260.0110.00026.35
8.1.250.0020.00528.09
8.1.240.0070.00323.86
8.1.230.0070.00322.23
8.1.220.0040.00417.88
8.1.210.0030.00618.77
8.1.200.0000.00817.47
8.1.190.0030.00617.50
8.1.180.0050.00318.10
8.1.170.0030.00517.62
8.1.160.0000.00719.01
8.1.150.0030.00518.98
8.1.140.0040.00422.25
8.1.130.0050.00220.25
8.1.120.0000.00917.56
8.1.110.0000.01017.54
8.1.100.0040.00417.62
8.1.90.0050.00217.50
8.1.80.0000.00817.49
8.1.70.0000.00917.57
8.1.60.0050.00317.60
8.1.50.0060.00317.60
8.1.40.0030.00517.52
8.1.30.0000.00817.79
8.1.20.0080.00017.73
8.1.10.0080.00017.62
8.1.00.0000.00817.53
8.0.300.0090.00018.77
8.0.290.0080.00016.88
8.0.280.0000.00718.54
8.0.270.0070.00016.91
8.0.260.0000.00718.52
8.0.250.0030.00517.13
8.0.240.0040.00417.04
8.0.230.0000.00717.14
8.0.220.0050.00316.93
8.0.210.0050.00217.05
8.0.200.0070.00017.00
8.0.190.0000.00817.02
8.0.180.0070.00017.06
8.0.170.0030.00517.10
8.0.160.0050.00317.07
8.0.150.0060.00316.98
8.0.140.0030.00517.05
8.0.130.0000.00613.53
8.0.120.0000.00817.00
8.0.110.0040.00417.00
8.0.100.0060.00317.13
8.0.90.0070.00017.02
8.0.80.0070.01017.07
8.0.70.0040.00416.87
8.0.60.0040.00416.92
8.0.50.0050.00216.90
8.0.30.0110.01017.14
8.0.20.0090.00917.40
8.0.10.0000.00817.08
8.0.00.0110.00716.87
7.4.330.0030.00315.55
7.4.320.0000.00616.77
7.4.300.0000.00616.67
7.4.290.0000.00716.70
7.4.280.0090.00016.52
7.4.270.0000.00716.73
7.4.260.0030.00316.59
7.4.250.0040.00416.58
7.4.240.0030.00516.54
7.4.230.0040.00416.77
7.4.220.0040.00416.79
7.4.210.0060.00816.70
7.4.200.0040.00416.50
7.4.160.0100.00916.66
7.4.140.0090.01017.86
7.4.130.0160.00316.57
7.4.120.0120.01016.64
7.4.110.0140.00616.64
7.4.100.0180.00516.57
7.4.90.0080.01216.55
7.4.80.0100.00919.39
7.4.70.0030.01316.83
7.4.60.0000.01716.60
7.4.50.0060.01116.72
7.4.40.0090.01216.71
7.4.00.0070.01015.00
7.3.330.0000.00513.36
7.3.320.0000.00613.49
7.3.310.0050.00316.40
7.3.300.0000.00716.32
7.3.290.0050.00316.50
7.3.280.0090.00916.51
7.3.260.0070.01016.59
7.3.240.0080.01316.54
7.3.230.0130.00616.69
7.3.210.0130.00416.58
7.3.200.0030.01616.38
7.3.190.0130.01016.82
7.3.180.0060.01016.63
7.3.170.0140.00416.67
7.3.160.0110.00516.79
7.2.330.0100.00716.65
7.2.320.0100.00916.77
7.2.310.0070.01017.01
7.2.300.0040.01316.82
7.2.290.0120.00616.54
7.2.120.0440.01014.96
7.2.110.0460.00714.68
7.2.100.0200.01314.80
7.2.90.0290.00614.82
7.2.80.0300.00914.69
7.2.70.0180.00915.03
7.2.60.0250.00914.76
7.2.50.0490.00914.99
7.2.40.0250.00715.06
7.2.30.0480.01114.80
7.2.20.0330.01014.84
7.2.10.0510.00614.90
7.2.00.0190.00915.16
7.1.240.0350.00413.74
7.1.230.0470.00613.82
7.1.220.0310.01013.96
7.1.210.0350.00713.70
7.1.200.0390.00413.83
7.1.190.0290.01013.61
7.1.180.0270.00813.57
7.1.170.1240.01013.64
7.1.160.0300.00713.61
7.1.150.0260.00713.63
7.1.140.0290.01013.62
7.1.130.0260.00613.61
7.1.120.0260.01113.83
7.1.110.0260.01013.64
7.1.100.0440.00313.86
7.1.90.0360.01013.94
7.1.80.0270.01413.69
7.1.70.0340.00613.61
7.1.60.0480.00713.71
7.1.50.0400.01013.81
7.1.40.0370.00313.83
7.1.30.0230.01313.57
7.1.20.0390.00713.85
7.1.10.0320.00613.79
7.1.00.0540.00313.68
5.6.380.0040.01213.49

preferences:
49.09 ms | 401 KiB | 5 Q