0

I am bit confused and not satisfied with the accepted answer here Does variable name length matter for performance in PHP?

Let me explain what i am trying to say.

PHP and ASP are both server side languages. Don't know much about ASP but as far as i know PHP complies the pages at run time. So if the page is contains long variable names or function names or how could that not matter to the compiler and so to the page output processing time. The compiler would read all the characters to the end of file before compiling for syntax and Symantec errors. correct me if i am wrong. So it means if the variable name is longer perhaps it will take more time for compiler to read them before processing hence increasing the compiling time and so run time.

<?php
//short variable name
$short="test";
echo $short;
?>

vs

<?php
//Long variable name
$long_long_long_long_long_variable_name="test";
echo $long_long_long_long_long_variable_name;
?>

So my Question is, in server side languages that compiles code when the user requests for the content, would it take more time to receive response from the server in such cases (long variable and method names)? A reference to a acceptable content or performance test is much preferred.

Please don't consider it as a duplicate as i wanted to clear out what i am trying to say, and want a reference/performance test and its also not considered as discussion as it matters with compiling time which wouldn't be changed upon with an opinion. This is here at stack overflow not at programmers as i want a performance test shown if possible.

Community
  • 1
  • 1
aimme
  • 6,385
  • 7
  • 48
  • 65
  • i knew i might get down voted? its ok. but commenting a valid reason is much preferred :) – aimme Sep 01 '15 at 08:16
  • What's preventing you from running a benchmark yourself? – Mat Sep 01 '15 at 08:23
  • 2
    Being a pragmatic person, PHP is an interpreted language. The PHP is compiled engine, but what ever program you create in PHP is interpreted. Interpreter need to read the code as it is and execute operations accordingly. Means that it will read variable names, pragmatically, the longer the name, the longer the time to read. But with current machine, the different between 5 character to 500 character variable names goes in a fraction of nano seconds... just an comment though. – Ferdinand Neman Sep 01 '15 at 08:23
  • @FerdinandNeman thank you. That's helping :) – aimme Sep 01 '15 at 08:24
  • 2
    If you're running a modern version of PHP, the bytecode will be cached anyway, so the few femtoseconds of difference in compilation will be a one-off anyway; even without opcache, it won't have any measurable effect on compilation speed – Mark Baker Sep 01 '15 at 08:25
  • 1
    It will have an effect on memory usage though, as the actual variable name is included as part of the bytecode, so long variable names will take more space in memory – Mark Baker Sep 01 '15 at 08:25
  • 2
    `It will have an effect on memory usage though` ...which might be a problem when running php on an arduino uno ;-) – VolkerK Sep 01 '15 at 08:27
  • @MarkBaker thank you. So it means it matters a little bit but not noticable? – aimme Sep 01 '15 at 08:28
  • 1
    `it matters a little bit but not noticable` - please define the theoratical threshold for "no, for all intents and purposes it doesn't matter" beforehand. "It matters" and "not noticable" is almost an oxymoron. – VolkerK Sep 01 '15 at 08:29
  • 1
    Not noticeable when executing the code, not even measurable in terms of speed; marginally noticeable in memory usage if you have a large number of very long variable names..... but I'd crucify any developer who used 500character variable names for creating unreadable code..... it's a case of don't worry about memory/speed, but use sensible names – Mark Baker Sep 01 '15 at 08:30
  • @MarkBaker so should i close this question? from the http://stackoverflow.com/questions/1408417/can-you-compile-php-code " I know that PHP is compiled to byte code before it is run on the server, and then that byte code can be cached so that the whole script doesn't have to be re-interpreted with every web access." . if its the case byte code would be very simplified? will variable name be shortened/small sized? – aimme Sep 01 '15 at 08:34
  • 1
    No, in the standard php enginge the variable names will be "in" the bytecode. It's still a runtime hashtable lookup. Different story with compilers like HipHop. – VolkerK Sep 01 '15 at 08:36
  • @Mat benchmark doesn't show references :) – aimme Sep 01 '15 at 08:38
  • 3
    So you're looking for someone to find references for you? That's what search engines are for, don't outsource your research here. Or do a benchmark for you? Give it a go first, show some effort. – Mat Sep 01 '15 at 08:42
  • @Mat No i searched a lot, even asked the lecturer :/. found a lot but was not able to accept it. so now i am trying to do bench marking. Thank you for the idea. but the question i was referring in this question doesn't clear those :) – aimme Sep 01 '15 at 08:46
  • 2
    "so now i am trying to do bench marking" - no, you're trying to get someone to benchmark for you, despite having already found (you linked to it) information that tells you this is pointless. If you want to do a benchmark, and can't find one already, get your hands on your keyboard and start coding. If you're stuck doing that, ask about it. – Mat Sep 01 '15 at 08:48
  • @Mat Much thanx :-) – aimme Sep 01 '15 at 08:51

0 Answers0