变数太​​多VS阵列 [英] Too many Variables vs Arrays

查看:83
本文介绍了变数太​​多VS阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个是从性能视图(CPU使用率等)更好?使用过多的变量或单个数组或者一般的阵列?

这一项:

  $ ld_linkdump_title = get_option('ld_linkdump_title');
$ ld_linkdump_widget_title = get_option('ld_linkdump_widget_title');
$ nw_option = get_option('ld_open_nw');
$ ld_open_branding = get_option('ld_open_branding');
$ ld_stylesheet_option = get_option('ld_stylesheet');
$ ld_number_of_links = get_option('ld_number_of_links');
$ ld_number_of_links_widget = get_option('ld_number_of_links_widget');
$ ld_number_of_rss_links = get_option('ld_number_of_rss_links');
$ ld_number_of_links_be = get_option('ld_number_of_links_be');
$ ld_repeated_link = get_option('ld_repeated_link');
$ ld_linkdump_fd = get_option('ld_linkdump_fd');
$ ld_linkdump_rss_desc = get_option('ld_linkdump_rss_desc');
$ ld_branding_bg = get_option('ld_branding_bg');
$ ld_archive_days = get_option('ld_archive_days');
$ ld_archive_pid = get_option('ld_archive_pid');
$ ld_show_counter = get_option('ld_show_counter');
$ ld_show_description = get_option('ld_show_description');
$ ld_show_description_w = get_option('ld_show_description_w');
$ ld_send_notification = get_option('ld_send_notification');
$ ld_auto_approve = get_option('ld_auto_approve');
$ ld_short_url = get_option('ld_short_url');

或本

  $选项['ld_linkdump_title'] = get_option('ld_linkdump_title');
$选项['ld_linkdump_widget_title'] = get_option('ld_linkdump_widget_title');
$选项['nw_option'] = get_option('ld_open_nw');
 。
 。
 。


解决方案

我不认为你应该从性能的角度考虑这个,而是看它从一个可读性的角度来看。第二个版本收集,好了,事情的集合,到一个单一的存储机制;从可读性的角度来看它的优越。

这不是问题,但是从性能的角度来看,我不能想象第二个成本太大,如果有的话,肯定是不够的,克服了可读性的利益。

Which one is better from performance view (CPU usage and etc)? using too many Variables or a single Associative Array or generally an Array?

This one:

$ld_linkdump_title         = get_option('ld_linkdump_title');
$ld_linkdump_widget_title  = get_option('ld_linkdump_widget_title');
$nw_option                 = get_option('ld_open_nw');
$ld_open_branding          = get_option('ld_open_branding');
$ld_stylesheet_option      = get_option('ld_stylesheet');
$ld_number_of_links        = get_option('ld_number_of_links');
$ld_number_of_links_widget = get_option('ld_number_of_links_widget');
$ld_number_of_rss_links    = get_option('ld_number_of_rss_links');
$ld_number_of_links_be     = get_option('ld_number_of_links_be');
$ld_repeated_link          = get_option('ld_repeated_link');
$ld_linkdump_fd            = get_option('ld_linkdump_fd');
$ld_linkdump_rss_desc      = get_option('ld_linkdump_rss_desc');
$ld_branding_bg            = get_option('ld_branding_bg');
$ld_archive_days           = get_option('ld_archive_days');
$ld_archive_pid            = get_option('ld_archive_pid');
$ld_show_counter           = get_option('ld_show_counter');
$ld_show_description       = get_option('ld_show_description');
$ld_show_description_w     = get_option('ld_show_description_w');
$ld_send_notification      = get_option('ld_send_notification');
$ld_auto_approve           = get_option('ld_auto_approve');
$ld_short_url              = get_option('ld_short_url');

or this:

$options['ld_linkdump_title'] = get_option('ld_linkdump_title');
$options['ld_linkdump_widget_title']  = get_option('ld_linkdump_widget_title');
$options['nw_option']                 = get_option('ld_open_nw');
 .
 .
 .

解决方案

I don't think you should consider this from a performance standpoint, rather, look at it from a readability standpoint. The second version collects, well, a collection of things, into a single storage mechanism; from a readability standpoint it's superior.

Not that it matters, but from a performance standpoint I can't imagine the second one costs much, if anything, certainly not enough to overcome the readability benefit.

这篇关于变数太​​多VS阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆