Original address: http://blog.sina.com.cn/s/blog_640b03390100sham.html
All along, the execution efficiency of the program is People's concern, in PHP is no exception, from the simplest quotation marks, but also thinking about his efficiency.
We have done experiments in particular, and we claim that the experiment may have been unprecedented and has not been followed.
Our experiment was based on the most elementary experimental methods: Cumulative method and multiple experiments to find the average.
Experiment one: Efficiency in the ordinary case
Our experiment was to execute a 10,000-byte file 5,000 times to get the speed of the parsing process.
First of all, this experiment specifically stipulates a unit, which is to better represent and eliminate the differences in the efficiency of the computer itself.
Time Unit TT, which represents about 7.2x10[sup]-8[/sup]s.
We obtained four sets of experimental data, which can be understood as the time when the ' a ' is faster than "a":
0.29 TT, about 0.0000000206s
0.46 TT, about 0.0000000328s
0.38 TT, about 0.0000000275s
0.41 TT, about 0.0000000292s
Average: 0.39 TT (' aaaa .... (139) ' efficiency close to ' AAA ... (100) ")
Conclusion: The use of single quotation marks is faster in the same amount of data and in normal cases (without escaping).
Experiment two: Efficiency of single-quote escaping
Our experiment was 5,000 times the same as "single quotes, double quotes" to execute two copies of the data, but one of them is specifically used to denote single quotes.
Time Unit TT, which represents about 7.2x10[sup]-8[/sup]s.
We obtained four sets of experimental data, which can be interpreted as saying "'" faster than "the time:
0.19 TT, about 0.0000000138s
0.15 TT, about 0.0000000110s
0.23 TT, about 0.0000000162s
0.24 TT, about 0.0000000173s
Average: 0.2 TT ("' ... (12) "Efficiency is close to" ... (10) ")
Conclusion: If you need to represent single quotes (MySQL queries) in a string, you should avoid escaping as much as possible, so use double quotes.
Experiment Three: The efficiency of curly braces
Our experiment was performed 1000 times with a certain number of variables tagged files, to obtain the speed of the parsing process.
Time Unit TT, which represents about 1.581x10[sup]-7[/sup]s~1.666x10[sup]-7[/sup]s. (TT change)
Get three sets of data, which means "{$ABC}" is faster than "$ABC".
15.3 TT, about 0.0000024186s
14.5 TT, about 0.0000024093s
15.3 TT, about 0.0000024152s
This data is very alarming, with an average result of TT.
This means: Use curly braces for parsing speed, about 16 times times less than curly braces.
Conclusion: The variable is represented in double quotation marks, and curly braces are used whenever possible.
Experiment four: continuous and discontinuous efficiency
Our experiment was performed 1000 times with a certain number of variables tagged files, to obtain the speed of the parsing process.
Time Unit TT, which represents about 1.581x10[sup]-7[/sup]s~1.666x10[sup]-7[/sup]s. (TT change)
The first set of experimental data, indicating "{$ABC} {$ABC} {$abc} ..." than $abc. $abc. $ABC Average resolution of each variable is fast
22.45 TT, about 0.0000035498s
21.03 TT, about 0.0000035037s
22.12 TT, about 0.0000034930s
Curly braces (continuous) are faster than single quotation marks (discontinuous), the average result is TT.
This means: Using curly braces, the parsing speed is approximately 23 times times the use of discontinuous single quotes.
Conclusion: In single quotes, multiple variables (or a small amount of data) are represented, as possible, with double references and curly braces.
The second set of experimental data shows that "... $abc $abc$abc ..." than ' ... $abc. $abc. $abc. ' ...‘ Average resolution of each variable is fast
7.15 TT, about 0.0000011311s
6.57 TT, about 0.0000010943s
6.83 TT, about 0.0000010777s
Double quotation marks (continuous) are faster than single quotation marks (discontinuous), with an average result of 7 TT. (This data changes)
This means: For a long time, the parsing speed using double quotation marks (without curly braces) is approximately 8 times times the use of discontinuous single quotes.
Conclusion: in double quotes, it is faster to use the "join operator" than the single quotation mark to denote multiple variables (or a small amount of data).
Conclusion: When you represent multiple variables (or a small amount of data), you should use double quotation marks in the range and use curly braces.
(Attached: The author speculates that this may have something to do with the allocation of memory space, which may cause memory to adjust continuously)
Final conclusion:
First, when you represent simple data (you don't need to escape), use single quotes as much as possible.
' Cal:are good at long? '
However, if you need to escape (that is, include single quotes) because you use single quotes, consider using double quotation marks.
' Cal:yes. But, you know, it ' s written. ' = ' cal:yes. But, you know, it ' s written. "
If you need to represent a variable, use curly braces whenever possible.
Cal: $to "=" cal: {$to}, you shouldn ' t go shopping. "
Try to make it continuous:
' Cal: '. $calsaid = "cal: $calsaid" = "cal: {$calsaid}"