in reply to CGI speed: one script versus many modules

alan,

This is a pretty good question. For timing scripts, I would recommend using Benchmark module (especially the code snippet shown in the new method). For benchmarking the importing of modules, that would be a little trickier since your probably using "use" which is a compile time directive. You could revert to loading your modules the old way ("require' and 'import') for timing.

That being said, there are two issues concerning modules versus "all-in-one" scripts (AIOS). AIOS are easier for end users to manage - especially with the disdain some hosting companies (or sysadmin teams) show in upgrading the perl lib. Modules are easier to maintain from a developer prospective. I prefer modules but some are getting pretty close to "dll hell" status and do not take advantage of the Autoloader.

In theory, modules would be slightly slower than AIOSes if every piece of code in the module is exercised. You save from a very small amount of load time for small modules to a very significant amount of time for large modules and many modules. The key here is import only the code you need. That can be accomplished by very wise module layout (and use) or by wise use of the Autoloader. You want to avoid importing code that will never be used by your script.

So my .02 cents would be to continue with what you're comfortable with especially if you have to maintain it. Also if your modules start to grow, use Autoloader to speed up your start time (and save on memory).

-derby

  • Comment on Re: CGI speed: one script versus many modules