inr*_*rob 3 php mysql variables
我有这个真正的新手问题:)
尽管如此
$lastInvoiceNumber
$lastInvNum
Run Code Online (Sandbox Code Playgroud)
要么:
last_invoice_number(int 10)
last_inv_num(int 10)
节省一点时间写.他们是否有任何好处(即使是最轻微的)
表现?
长与短?
如果查询具有较短的表列名称,
有没有机会php和MySQL更重要的是会消耗
更少的内存?
例如,如果我必须在单个查询中获取500行,我想象
查询将运行500次并运行
last_invoice_number500次
与运行相比
last_inv_num可以节省一些内存或使事情稍微快一点.
谢谢.
不,无论如何都没有明显的性能差异,并且通过使用描述性变量名称,您将在可读性方面获得巨大的提升.在内部,这些变量由内存地址引用(简单地说),而不是它们的ASCII/Unicode名称.它几乎可以用任何语言对性能产生的影响是如此微不足道,以至于它永远不会被注意到.
编辑:
我添加了一个基准.它表明,使用单个字母作为变量名称和使用17个字符的变量名称之间确实没有任何区别.单个字母甚至可能会慢一点.但是,我注意到在使用90个字符的变量名时,时间略有不断增加,但实际上,差异太小,无法注意到.这是基准和输出:
<?php
# To prevent any startup-costs from skewing results of the first test.
$start = microtime(true);
for ($i = 0; $i<1000; $i++)
{
$noop = null;
}
$end = microtime(true);
# Let's benchmark!
$start = microtime(true);
for ($i = 0; $i<1000000; $i++)
{
$thisIsAReallyLongAndReallyDescriptiveVariableNameInFactItIsJustWayTooLongHonestlyWtf = mt_rand(0, 1000);
}
$end = microtime(true);
printf("Using a long name took %f seconds.\n", ($end - $start));
$start = microtime(true);
for ($i = 0; $i<1000000; $i++)
{
$thisIsABitTooLong = mt_rand(0, 1000);
}
$end = microtime(true);
printf("Using a medium name took %f seconds.\n", ($end - $start));
$start = microtime(true);
for ($i = 0; $i<1000000; $i++)
{
$t = mt_rand(0, 1000);
}
$end = microtime(true);
printf("Using a short name took %f seconds.\n", ($end - $start));
Run Code Online (Sandbox Code Playgroud)
输出:
$ php so-test.php
Using a long name took 0.148200 seconds.
Using a medium name took 0.142286 seconds.
Using a short name took 0.145952 seconds.
Run Code Online (Sandbox Code Playgroud)
MySQL也是如此; 我几乎可以保证,但基准测试并不容易.使用MySQL,您将从网络和IO获得比代码中符号命名更多的开销.就像PHP一样,在内部,列名不仅仅是迭代的字符串; 数据以高效存储器格式存储.
| 归档时间: |
|
| 查看次数: |
116 次 |
| 最近记录: |