2010年10月31日星期日

[fw-mvc] Re: Auto HTML escaper module for Zend_View.

My module doesn't parse any files. It just utilizes the power of SPL &
Predefined Interfaces.
http://www.php.net/manual/en/book.spl.php
http://www.php.net/manual/en/reserved.interfaces.php

I have just checked the performance of my view with ab command.
* Intel(R) Xeon(R) CPU L5520 @ 2.27GHz

The results of $ ab -c 5 -n 50.

=== Zend_View

Time taken for tests: 1.721591 seconds
Requests per second: 29.04 [#/sec] (mean)
Time per request: 172.159 [ms] (mean)
Time per request: 34.432 [ms] (mean, across all concurrent requests)
Transfer rate: 426.35 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 160 170 5.3 170 184
Waiting: 156 167 5.1 167 180
Total: 160 170 5.3 170 184


=== My auto escaper

Time taken for tests: 1.772377 seconds
Requests per second: 28.21 [#/sec] (mean)
Time per request: 177.238 [ms] (mean)
Time per request: 35.448 [ms] (mean, across all concurrent requests)
Transfer rate: 414.70 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 2
Processing: 160 175 6.3 175 194
Waiting: 157 171 5.6 172 187
Total: 160 175 6.3 175 194


The overhead is bearable for me.
Like you, I hated using preg_* and parsing view files because I thought it
was tremendously slow.
But the truth is that trapping a view file and parsing it with
Zend_View_Stream isn't that slow. (I just have checked it!)

Then the only drawback of it is you could apply any arbitrary rules to your
view files, like writing <% ... %> instead of <?php ... ?>, <?php foreach
... ?> instead of <? loop ... ?>.
If you do so, they aren't 'PHP' any more.

But if you don't care about what your templates look like, Zend_View_Stream
is better way.
And to tell the truth, I don't care, either...

--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Auto-HTML-escaper-module-for-Zend-View-tp3019090p3020887.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: