Re: NewEra performance difference between base types and object types
Posted in 1996
ftv@tglobe1.tollpost.no (Frode Tvedten) wrote: > ... > I modified it to run the test for 'VAR1 += VAR2'. >Now the object type was five times SLOWER than the base type, which ran >with the same speed as before. > >I suppose there is a better way to program this, to get the object-code >run >faster (Tell me if you know). -But I still think OO-programming is >taking >a few steps to far converting simple data types as integers into >objects. > There is a way to make it faster: Instead of using ixIntegerVariable.getValueStr(), simply use ixIntegerVariable.value Why convert the integer's value to character and than to a decimal for the computation? >My modification of the program added: > >------------ >include system "ixnum.4gh" > >main > variable anInt1 ixInteger(0) > variable anInt2 integer = 0 > variable anInt3 ixInteger(2) > variable anInt4 integer = 2 > variable aCount integer > > display "start" > > -- dummy loop to see cost of for loop > display current second to fraction(2) > for aCount = 1 to 1000 > end for > > -- use object type > display current second to fraction(2) > for aCount = 1 to 1000 > call anInt1.plus(anInt3.getValueStr()) Right here change it to: call anInt1.plus(anInt3.value) > end for > > -- use base type > display current second to fraction(2) > for aCount = 1 to 1000 > let anInt2 = anInt2 + anInt4 > end for > > display current second to fraction(2) > display "finish " > return > >end main > > The ixInteger math is still about 2.5 faster ('C' compiled). Also, since using a public member variable (value) is not too O-O, I created another test where I derived the ixInteger class to a new class, anInteger, and added a member function getValue() that returns an integer: call anInt1.plus(anInt3.getValue()) The benchmark results were similar (about 2.5 times faster) Catalin -- ========================================================================= Catalin Badea _/_/_/ _/_/_/ _/_/_/ _/_/_/ _/ _/ _/_/_/ _/ _/ _/ _/ _/_/ _/ Senior Technical Architect _/ _/_/ _/ _/_/_/ _/ _/_/_/ _/ _/ _/ _/ _/ _/ Tecsys Inc. _/ _/_/_/ _/_/_/ _/_/_/ _/ _/_/_/ ===== cat@tecsys.com =========== include system "disclaimer.4gh" ===== == http://www.virtualmarketplace.com/LEVEL3/ITEC/TECSYSE/TECSYSE.HP === # anint.4gh include system "ixnum.4gh" class anInteger derived from ixInteger function anInteger ( value INTEGER: NULL ) function getValue() returning integer end class # anint.4gl include "anint.4gh" function anInteger::anInteger ( value INTEGER) : ixInteger( value : value) end function function anInteger::getValue() returning integer return value end function