in reply to Re: Re: BitStream revisited
in thread BitStream revisited
There is nothing wrong with OO. I like it and use it. Your initial question concerned speed ie can this be made faster. Answer yes ditch the OO. OO perl is 30-40% slower than using raw function calls - just to do the same call. If you have other requirements that mandate OO then you have other requirements.....
If you will only have a single instance of your bitstream object then you can easily just do:
{ # hold state stuff in a closure # this can be identical to an object hash data # but you only get one instance at any one time # with this simple setup my %state; sub get { } sub seek_pos { } # set your %state with init like new sub init { } }
That will be 30-40% faster than OO with the same data encapsulation but limited to one instance. It all depends on the application. Like I said initially if speed really matters I would hack it up in C but that would take time. As always it is a tradeoff between hardware cost/head down coding time/oo convenince etc. A lot of problems can be solved quickly with Perl and made fast enough by throwing more memory and cycles at it to get the required performance. Applying more grunt to relatively inefficient code is a practical real world solution. Just ask M$ and intel.
cheers
tachyon
|
|---|