Advertisement
Guest User

replace.php

a guest
Jul 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. $nickname = "xISRAPILx";
  3. $balance = 150000;
  4. $clan = "CloudMine";
  5.  
  6. $text = "Привет, {NICKNAME}, ваш баланс: {BALANCE}, Ваш клан: {CLAN}";
  7.  
  8. $keys = ["{NICKNAME}", "{BALANCE}", "{CLAN}"];
  9. $values = [$nickname, $balance, $clan];
  10.  
  11. $key_values = ["{BALANCE}" => $balance, "{NICKNAME}" => $nickname, "{CLAN}" => $clan];
  12.  
  13. $startTime = microtime(true);
  14. for($i = 0; $i < 500000; $i++){
  15.     str_replace($keys, $values, $text);
  16. }
  17. echo "500000 str_replace + keys array + values array: ".round(microtime(true) - $startTime, 5).PHP_EOL;
  18.  
  19. $startTime = microtime(true);
  20. for($i = 0; $i < 500000; $i++){
  21.     str_replace(array_keys($key_values), array_values($key_values), $text);
  22. }
  23. echo "500000 str_replace + array_keys + array+values: ".round(microtime(true) - $startTime, 5).PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement