Polymorphism's effect on efficiency
I am trying to measure the effect of OO principles (encapsulation, inheritance, and polymorphism) on a program's efficiency. I am basically creating two separate applications that do the same thing but are architecturally different, executing them, then comparing running times.
For an example, I'm testing the efficiency of a class with getters and setters against the efficiency of a class which performs the same tasks, but whose members are public (and thus accessed via Foo.memberName instead of Foo.getMember()).
I'm currently having trouble creating a test case for polymorphism which can show that using polymorphism is more costly than not efficiency-wise.My problem is that with simple classes I can't seem to really see a performance hit. Does anyone know which polymorphic elements/structures/practices will have the greatest effect on efficiency? And, do you have any ideas as to how I can exploit them in a simple example?
After you are done with your performance tests are you also going to do maintainability and time-to-market tests (especially on non-trivial codebases)?
I'm sure your tests will show that greater levels of abstraction (I consider OO to be a greater level of abstraction than, say, a procedural approach) come with some performance impact.
However, I'm convinced that the performance penalty is small enough to be outweighed thousandfold by the ease of development and maintenance offered by the higher level of abstraction.
If not, we'd all be programming assembly language.
> If not, we'd all be programming assembly language.
case in point.
i always argue (and have faith) in the idea that people migrate
to better ideas and the less successful ones fall away -
so if we werent getting benefits from todays practices
we wouldnt have migrated to them.
we'd be like he said literally pushing bits. ; )
>the fact that you can pull that out on command scares me ; )You can't say I'm not well read...Really, though, I just read about it the other day when 1.5_08 was released and it stuck in my mind. Don't worry, it will be gone in another month or two.
Herko_ter_Horst: The tests are only research. I can assure you that I'm a firm believer in the long-term benefits of OOP-developed applications. I am more or less just trying to quantify the effects of polymorphism. However, as you've pointed out, the extra clock ticks I might squeeze from some structureless code do not compensate for the real-world benefits of structured code.
IanSchneider: Thanks. This gives me a great starting point.
> I'm currently having trouble creating a test case for polymorphism
> which can show that using polymorphism is more costly than not
> efficiency-wise.
So does this mean you already have test cases where polymorphism is cheaper than, um, monomorphism? Or do I detect a bias in your methodology?