in reply to Time efficiency of object creation in Perl (or the "bless" function)
ended up taking about half a day to run as opposed to the 30 seconds
Given the 144,000% slowdown you've described, I surprised that you need to ask :)
If your processing is cpu-intensive, the simple answer is no. And the more sophisticated the OO, the worse it gets.
If your application is IO-bound--web work; DB work or highly interactive--then you can "get away with it", but for anything requiring real processing with time pressure, you're better off without OO in Perl.
There are ways to mitigate some of the problems you've encountered. For most applications requiring 1000s of entities, those entities tend to group naturally into sets or collections, with the same processing being applied to whole collections rather than individual entities.
If you design your classes such that they represent a complete set of similar entities (stored internally as an array or hash), and the methods process the entire set, or large subsets--ie. you move the loops internal to the methods--then the OO overheads get amortised across large volumes of processing and so become minimal in the overall scheme of things.
This makes a lot of sense in other ways also. It is rare for an application that manipulates 1000s of objects to name them all individually. You almost always end up putting the object refs into arrays in order to loop over them. So, moving the arrays inside the OO and having methods that process the internal array of entities (not objects) either en-masse; or in large range-defined chunks, can yield benefits of clearer code structure at both the caller and internal levels. And that is after all the best reason for using OO.
But OO for its own sake is pointless at best; and if there is a timeliness component to your application spec, something far more detrimental.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Time efficiency of object creation in Perl (or the "bless" function)
by kikumbob (Novice) on Jun 03, 2011 at 11:10 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2011 at 14:46 UTC |