Created
September 2, 2017 20:48
-
-
Save MaxymVlasov/062198f16d2f3b00b0c209f8f0802277 to your computer and use it in GitHub Desktop.
PHP native with algoritms vs C++ on PHP
This file contains hidden or 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 declare(strict_types=1); | |
var_dump('for, 1000000 iteration'); | |
$start=microtime(true); | |
for ($j = 0; $j < 1000000; $j++) { | |
$str8Byte = 'Str8byte'; | |
$str1KB = $str8Byte; | |
# 8B = 2^3, 1KB = 2^10 | |
for ($i = 3; $i < 10; $i++) { | |
$str1KB = $str1KB.$str1KB; | |
} | |
$tenKBData = str_repeat($str1KB, 10); | |
} | |
$end = microtime(true); | |
var_dump($end - $start); | |
This file contains hidden or 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 declare(strict_types=1); | |
var_dump('func, 1000000 iteration'); | |
$start=microtime(true); | |
for ($j = 0; $j < 1000000; $j++) { | |
$start=microtime(true); | |
$str8Byte = 'Str8byte'; | |
$tenKBData = str_repeat($str8Byte, 1280); | |
} | |
$end = microtime(true); | |
var_dump($end - $start); |
This file contains hidden or 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
string(22) "for, 1000000 iteration" | |
float(0.61288499832153) | |
string(23) "func, 1000000 iteration" | |
float(3.814697265625E-6) | |
string(22) "for, 1000000 iteration" | |
float(0.6605429649353) | |
string(23) "func, 1000000 iteration" | |
float(4.0531158447266E-6) | |
string(22) "for, 1000000 iteration" | |
float(0.70987796783447) | |
string(23) "func, 1000000 iteration" | |
float(5.0067901611328E-6) | |
string(22) "for, 1000000 iteration" | |
float(0.62938618659973) | |
string(23) "func, 1000000 iteration" | |
float(5.0067901611328E-6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment