For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > April 2004 > Vote: PEAR::Strip_Comments









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Vote: PEAR::Strip_Comments
Thorsten Suckow-Homberg

2004-04-28, 4:45 pm

Since the PEAR-(Package-)Class-Files get bigger with every comment and
phpDoc-Code you add to your file, I thought of an automatism that strips
those comments for the use in a productive environment.
This would result in a faster access and reducing overhead because of
loading files which source-code exists to ~60% of comments and
documentation.

I thought of putting a method into the PEAR.php-file which works like the
following:

//in PEAR.php (code is simplified)
function get_stripped($sFileName)
{
if (!file_exists($sFileName.".stripped.php")
|| file_mtime($sFileName) > file_mtime($sFileName.".stripped.php")) {
delete_all_comments_in_the_file_to_reduc
e_filesize($sFileName);
save_the_file_under($sFileName.".stripped.php");
}

return $sFileName.".stripped";
}

//and in your code (and the PEAR-classes could/ should use this, too)
require_once PEAR::get_stripped("greatPEARClass.php");

This would reduce file-size of some classes up to 50%.

What do you think of it? Great performance-improvement or "useless-to-have"?
Alan Knowles

2004-04-28, 10:06 pm

This is a mute issue.. -

if you are concerned about performance, and are not using a cache..
(which solves this isssue) - its a bit like building a house with only a
spoon...

Regards
Alan

Thorsten Suckow-Homberg wrote:
> Since the PEAR-(Package-)Class-Files get bigger with every comment and
> phpDoc-Code you add to your file, I thought of an automatism that strips
> those comments for the use in a productive environment.
> This would result in a faster access and reducing overhead because of
> loading files which source-code exists to ~60% of comments and
> documentation.
>
> I thought of putting a method into the PEAR.php-file which works like the
> following:
>
> //in PEAR.php (code is simplified)
> function get_stripped($sFileName)
> {
> if (!file_exists($sFileName.".stripped.php")
> || file_mtime($sFileName) > file_mtime($sFileName.".stripped.php")) {
> delete_all_comments_in_the_file_to_reduc
e_filesize($sFileName);
> save_the_file_under($sFileName.".stripped.php");
> }
>
> return $sFileName.".stripped";
> }
>
> //and in your code (and the PEAR-classes could/ should use this, too)
> require_once PEAR::get_stripped("greatPEARClass.php");
>
> This would reduce file-size of some classes up to 50%.
>
> What do you think of it? Great performance-improvement or "useless-to-have"?

Alan Knowles

2004-04-28, 10:06 pm

This is a mute issue.. -

if you are concerned about performance, and are not using a cache..
(which solves this isssue) - its a bit like building a house with only a
spoon...

Regards
Alan

Thorsten Suckow-Homberg wrote:
> Since the PEAR-(Package-)Class-Files get bigger with every comment and
> phpDoc-Code you add to your file, I thought of an automatism that strips
> those comments for the use in a productive environment.
> This would result in a faster access and reducing overhead because of
> loading files which source-code exists to ~60% of comments and
> documentation.
>
> I thought of putting a method into the PEAR.php-file which works like the
> following:
>
> //in PEAR.php (code is simplified)
> function get_stripped($sFileName)
> {
> if (!file_exists($sFileName.".stripped.php")
> || file_mtime($sFileName) > file_mtime($sFileName.".stripped.php")) {
> delete_all_comments_in_the_file_to_reduc
e_filesize($sFileName);
> save_the_file_under($sFileName.".stripped.php");
> }
>
> return $sFileName.".stripped";
> }
>
> //and in your code (and the PEAR-classes could/ should use this, too)
> require_once PEAR::get_stripped("greatPEARClass.php");
>
> This would reduce file-size of some classes up to 50%.
>
> What do you think of it? Great performance-improvement or "useless-to-have"?

Thorsten Suckow-Homberg

2004-04-30, 3:07 am

> if you are concerned about performance, and are not using a cache..
> (which solves this isssue) - its a bit like building a house with only a
> spoon...


Well, there are people who cannot run a cache on their server (security
restrictions, no money etc. pp.).

This is just a call for "what do you think of it" and "would it increase the
performance", nothing else ;).

I may port this idea to a class that obfuscates JavaScript-Code. However,
I'm interested in that what people say. So keep it coming ;)

And btw.: There definitely is a diference in the speed:

HUGE_FILE.php (5234 lines of comments without code to interpret)
========================================
=========
["mean"]=> string(8) "0.037905"
["iterations"]=> int(100)

SMALL_FILE.php (2631 lines of comments without code to interpret)
========================================
=========
["mean"]=> string(8) "0.019446"
["iterations"]=> int(100)


I used the following code to test:

<?php
require_once 'Benchmark/Iterate.php';
$benchmark = new Benchmark_Iterate;

function foo()
{
//require("HUGE_FILE.php");
require("SMALL_FILE.php");
}

$benchmark->run(100, 'foo');




$result = $benchmark->get();

echo "<hr>";
var_dump($result);
?>
Thorsten Suckow-Homberg

2004-04-30, 3:07 am

> if you are concerned about performance, and are not using a cache..
> (which solves this isssue) - its a bit like building a house with only a
> spoon...


Well, there are people who cannot run a cache on their server (security
restrictions, no money etc. pp.).

This is just a call for "what do you think of it" and "would it increase the
performance", nothing else ;).

I may port this idea to a class that obfuscates JavaScript-Code. However,
I'm interested in that what people say. So keep it coming ;)

And btw.: There definitely is a diference in the speed:

HUGE_FILE.php (5234 lines of comments without code to interpret)
========================================
=========
["mean"]=> string(8) "0.037905"
["iterations"]=> int(100)

SMALL_FILE.php (2631 lines of comments without code to interpret)
========================================
=========
["mean"]=> string(8) "0.019446"
["iterations"]=> int(100)


I used the following code to test:

<?php
require_once 'Benchmark/Iterate.php';
$benchmark = new Benchmark_Iterate;

function foo()
{
//require("HUGE_FILE.php");
require("SMALL_FILE.php");
}

$benchmark->run(100, 'foo');




$result = $benchmark->get();

echo "<hr>";
var_dump($result);
?>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com