Оптимизировать код php
Имеется данный код, его задача искать совпадения, даже частичные, в массиве игнорируя символы и разницу в регистре, учитывает только точки и дефисы.
Надо без потери производительности сделать его короче. Можно менять функции, принцип, главное чтобы вход и выход работали также как сейчас.
Присылайте стоимость оптимизации и кол-во символов в которое сможете уложиться, будет выбрано наименьшее.
<?php
$start = microtime(true);
function search_converter($value): string
{
$converter = array(
'а' => 'f', 'б' => ' ', 'в' => 'd', 'г' => 'u', 'д' => 'l', 'е' => 't', 'ё' => ' ',
'ж' => ' ', 'з' => 'p', 'и' => 'b', 'й' => 'q', 'к' => 'r', 'л' => 'k', 'м' => 'v',
'н' => 'y', 'о' => 'j', 'п' => 'g', 'р' => 'h', 'с' => 'c', 'т' => 'n', 'у' => 'e',
'ф' => 'a', 'х' => ' ', 'ц' => 'w', 'ч' => 'x', 'ш' => 'i', 'щ' => 'o', 'ь' => 'm',
'ы' => 's', 'ъ' => ' ', 'э' => ' ', 'ю' => '.', 'я' => 'z',
'А' => 'F', 'Б' => ' ', 'В' => 'D', 'Г' => 'U', 'Д' => 'L', 'Е' => 'T', 'Ё' => ' ',
'Ж' => ' ', 'З' => 'P', 'И' => 'B', 'Й' => 'Q', 'К' => 'R', 'Л' => 'K', 'М' => 'V',
'Н' => 'Y', 'О' => 'J', 'П' => 'G', 'Р' => 'H', 'С' => 'C', 'Т' => 'N', 'У' => 'E',
'Ф' => 'A', 'Х' => ' ', 'Ц' => 'W', 'Ч' => 'X', 'Ш' => 'I', 'Щ' => 'O', 'Ь' => 'M',
'Ы' => 'S', 'Ъ' => ' ', 'Э' => ' ', 'Ю' => '>', 'Я' => 'Z',
'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g',
'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n',
'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u',
'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z',
'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', 'F' => 'F', 'G' => 'G',
'H' => 'H', 'I' => 'I', 'J' => 'J', 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N',
'O' => 'O', 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T', 'U' => 'U',
'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y', 'Z' => 'Z',
'"' => ' ', '$' => ' ', ':' => ' ', '^' => ' ', ',' => ' ', '\'' => ' ', '@' => ' ',
'№' => ' ', '#' => ' ', ';' => ' ', '?' => ' ', '&' => ' ', '/' => ' ', '~' => ' ',
'+' => ' ', '}' => ' ', '{' => ' ', '[' => ' ', ']' => ' ', '!' => ' ', '%' => ' ',
'(' => ' ', ')' => ' ', '<' => ' ', '>' => ' '
);
$value = strtr($value, $converter);
$value = mb_strtolower($value);
$value = '/[A-Za-z0-9\s.]*(' . str_replace(' ', ')[A-Za-z0-9\s.]*(', $value) . ')[A-Za-z0-9\s.]*/';
return $value;
}
function search($search, $value)
{
return preg_match($search, $value, $matches);
}
$search = search_converter('DRA S');
$arr = array('Boss', 'Lentins', 'NAV', 'Endless', 'Dragons', 'SiLeNT', 'Doctors', 'Lynx');
$result = [];
foreach ($arr as $item) {
if (search($search, mb_strtolower($item))) {
$result = $item;
}
}
print_r($result);
echo 'Время выполнения скрипта: ' . round(microtime(true) - $start, 4) . ' сек.';
-
146 2 0 нашел 2 места где можно оптимизировать
вот ваш код
https://inlnk.ru/Wo6yd
и мой
https://inlnk.ru/WMKAe
правда по функции microtime такой маленький запрос не определить
-
Здравствуйте, так а где "данный код"?)
-
Не очень понял, необходимо сократить количество кода, или время выполнения?
-
Current freelance projects in the category PHP
Looking for a Bitrix24 specialist / CRM integrator to set up automation.Our company works with CRM Bitrix24. We need a specialist who can set up automatic addition of phone numbers to leads/orders in two formats. Automation must be correctly configured for two countries: the Republic of Moldova and Romania. Task: When creating a lead or order in… PHP, Web Programming ∙ 13 hours 21 minutes back ∙ 22 proposals |
Add a scrolling marquee to the header of the website
16 USD
https://crazybox.com.ua/uk?srsltid=AfmBOopQRUXCCmxx699n57B3eP1XmwcYxJxwPh9qV9WcVjLjS_J2pK5s here is an example of how it looks, it needs to be made similar to theirs and on this one it needs to be done https://rollershop.com.ua/ opencart ocStore 3.0.3.7. and there should be… PHP, Web Programming ∙ 1 day 6 hours back ∙ 87 proposals |
Website optimizationOptimization of the website jdgreta.co.uk on Shopify. SEO audit attached to the project. Main tasks - - Fix all meta data - Complete the technical specifications for the programmer (since this project combines tasks for both the programmer and SEO, if you are not a company -… HTML & CSS, PHP ∙ 1 day 9 hours back ∙ 30 proposals |
Horoshop SpecialistNeed a specialist who can correctly set up the product Feed. Problem: Currently, over 13,000 products are being uploaded with the same type value (e.g., "everything for manicure and pedicure"). Because of this, it is impossible to segment products in Google Ads and set different… PHP, Website Maintenance ∙ 2 days 11 hours back ∙ 21 proposals |
Make sure that order emails from the store do not go to spam.Currently, there is a store on OpenCart, and order emails are landing in spam. We need to ensure they go to Inbox (ukr.net gmail) and check it. The hosting provider wrote: Poor email delivery may be related to a low sender reputation - IP or domain. In this case, we can advise… PHP, Web Programming ∙ 3 days 13 hours back ∙ 47 proposals |