Strange performance effects

Discussion in 'C++' started by Roland, Jan 20, 2004.

  1. Roland

    Roland Guest

    Hi!

    I am working on a project in which i implement a mathematical
    optimization algorithm. One of the requirements on the code is very
    good performance. So i started to optimize a bit. Now i do have a very
    strange effect which i do not understand. Maybe somebody knows about:

    I have the following class

    template<class T> class SimplexL2Penalty : public Function<T,T>
    {
    public:

    ASIString GetTypeInfo() const;
    SimplexL2Penalty(const Simplex<T>& simplex);
    SimplexL2Penalty(const Simplex<T>& simplex,const T& weight);
    SimplexL2Penalty(const Simplex<T>& simplex,const Vector<T>&
    w);
    SimplexL2Penalty(const SimplexL2Penalty& toBeCopied);
    virtual ~SimplexL2Penalty();
    T Evaluate(const Vector<T>& point) const;
    void operator*= (const T& factor);
    ASIString ToXML() const;
    Function<T,T>* ConstructCopy() const;
    ASI_FLOGIC LargerOrEqual(const T& value) const;
    const VectorSet<T>* GetZeroSet();

    protected:

    Vector<T> ComputePerturbation(const Vector<T>& point) const;
    Simplex<T> m_Simplex;
    T* m_WeightVector;
    T m_Factor;

    //Vector<T> *m_PerturbationVector1;
    };

    This class is used in an iterative algorithm. Performance is about 500
    iterations per second.
    When i add the pointer m_PerturbationVector1 to the class (without
    using it at all) performance drops to 250 iterations per second.

    What is going on? What can i do to overcome this effect.

    Thanks a lot,
    Roland

    PS: I am using Microsoft Visual C++ 6.0.
    Roland, Jan 20, 2004
    #1
    1. Advertising

  2. "Roland" <> wrote...
    > I am working on a project in which i implement a mathematical
    > optimization algorithm. One of the requirements on the code is very
    > good performance. So i started to optimize a bit. Now i do have a very
    > strange effect which i do not understand. Maybe somebody knows about:
    >
    > I have the following class


    Actually, it's a template.

    >
    > template<class T> class SimplexL2Penalty : public Function<T,T>
    > {
    > public:
    >
    > ASIString GetTypeInfo() const;
    > SimplexL2Penalty(const Simplex<T>& simplex);
    > SimplexL2Penalty(const Simplex<T>& simplex,const T& weight);
    > SimplexL2Penalty(const Simplex<T>& simplex,const Vector<T>&
    > w);
    > SimplexL2Penalty(const SimplexL2Penalty& toBeCopied);
    > virtual ~SimplexL2Penalty();
    > T Evaluate(const Vector<T>& point) const;
    > void operator*= (const T& factor);
    > ASIString ToXML() const;
    > Function<T,T>* ConstructCopy() const;
    > ASI_FLOGIC LargerOrEqual(const T& value) const;
    > const VectorSet<T>* GetZeroSet();
    >
    > protected:
    >
    > Vector<T> ComputePerturbation(const Vector<T>& point) const;
    > Simplex<T> m_Simplex;
    > T* m_WeightVector;
    > T m_Factor;
    >
    > //Vector<T> *m_PerturbationVector1;
    > };
    >
    > This class is used in an iterative algorithm.


    How? Don't you think it might matter?

    > Performance is about 500
    > iterations per second.
    > When i add the pointer m_PerturbationVector1 to the class (without
    > using it at all) performance drops to 250 iterations per second.
    >
    > What is going on?


    Who the hell can tell? Without seeing how the template is used, your
    guess is just as good as ours. It could be that the size causes some
    kind of processor cache to be blown away more often, it could be that
    allocating a bunch of them now requires more OS involvement... There
    is no way to tell for certain.

    > What can i do to overcome this effect.


    Don't declare that member, since you're not using it.

    Why don't you take a profiler and run your process through it with and
    without the member. See if you can spot the difference. Then analyse.
    Then come back and ask for assistance if you still need it.

    Victor
    Victor Bazarov, Jan 20, 2004
    #2
    1. Advertising

  3. Roland

    Roland Guest

    "Victor Bazarov" <> wrote in message news:<Lx1Pb.88602$5V2.150409@attbi_s53>...
    > "Roland" <> wrote...
    > > I am working on a project in which i implement a mathematical
    > > optimization algorithm. One of the requirements on the code is very
    > > good performance. So i started to optimize a bit. Now i do have a very
    > > strange effect which i do not understand. Maybe somebody knows about:
    > >
    > > I have the following class

    >
    > Actually, it's a template.
    >
    > >
    > > template<class T> class SimplexL2Penalty : public Function<T,T>
    > > {
    > > public:
    > >
    > > ASIString GetTypeInfo() const;
    > > SimplexL2Penalty(const Simplex<T>& simplex);
    > > SimplexL2Penalty(const Simplex<T>& simplex,const T& weight);
    > > SimplexL2Penalty(const Simplex<T>& simplex,const Vector<T>&
    > > w);
    > > SimplexL2Penalty(const SimplexL2Penalty& toBeCopied);
    > > virtual ~SimplexL2Penalty();
    > > T Evaluate(const Vector<T>& point) const;
    > > void operator*= (const T& factor);
    > > ASIString ToXML() const;
    > > Function<T,T>* ConstructCopy() const;
    > > ASI_FLOGIC LargerOrEqual(const T& value) const;
    > > const VectorSet<T>* GetZeroSet();
    > >
    > > protected:
    > >
    > > Vector<T> ComputePerturbation(const Vector<T>& point) const;
    > > Simplex<T> m_Simplex;
    > > T* m_WeightVector;
    > > T m_Factor;
    > >
    > > //Vector<T> *m_PerturbationVector1;
    > > };
    > >
    > > This class is used in an iterative algorithm.

    >
    > How? Don't you think it might matter?
    >
    > > Performance is about 500
    > > iterations per second.
    > > When i add the pointer m_PerturbationVector1 to the class (without
    > > using it at all) performance drops to 250 iterations per second.
    > >
    > > What is going on?

    >
    > Who the hell can tell? Without seeing how the template is used, your
    > guess is just as good as ours. It could be that the size causes some
    > kind of processor cache to be blown away more often, it could be that
    > allocating a bunch of them now requires more OS involvement... There
    > is no way to tell for certain.
    >
    > > What can i do to overcome this effect.

    >
    > Don't declare that member, since you're not using it.
    >
    > Why don't you take a profiler and run your process through it with and
    > without the member. See if you can spot the difference. Then analyse.
    > Then come back and ask for assistance if you still need it.
    >
    > Victor


    Thank you. Clearly i will not declare a member when not using it. On
    the long run i will use it.

    Since i am a mathematican i do not know much about technical aspects.
    Obviously nobody can answer the question in detail using the
    information provided. But some may guess what it could be. Just as you
    did. And then i migth be able to look for a book or something to learn
    about. That is what i hoped for.

    Roland
    Roland, Jan 20, 2004
    #3
  4. Roland

    Chris Theis Guest

    "Roland" <> wrote in message
    news:...
    [SNIP]
    > Thank you. Clearly i will not declare a member when not using it. On
    > the long run i will use it.
    >
    > Since i am a mathematican i do not know much about technical aspects.
    > Obviously nobody can answer the question in detail using the
    > information provided. But some may guess what it could be. Just as you
    > did. And then i migth be able to look for a book or something to learn
    > about. That is what i hoped for.


    Sorry to disappoint you but guessing and optimization are two terms that
    don't match very well. The whole problem starts with the term "optimizing a
    bit". I'd recommend to profile your program first to determine where the
    real bottleneck is before starting to fiddle around with the code. Keep in
    mind that premature optimization is something that might even fire back!

    Regards
    Chris
    Chris Theis, Jan 20, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Bancroft
    Replies:
    2
    Views:
    2,397
    =?Utf-8?B?UmFodWwgQW5hbmQ=?=
    Dec 28, 2004
  2. =?Utf-8?B?RGFu?=
    Replies:
    7
    Views:
    1,012
  3. Alex Molochnikov
    Replies:
    0
    Views:
    442
    Alex Molochnikov
    Oct 6, 2005
  4. Rogério Brito
    Replies:
    1
    Views:
    659
    Sean DiZazzo
    Sep 9, 2009
  5. Avdi B. Grimm
    Replies:
    0
    Views:
    99
    Avdi B. Grimm
    Oct 5, 2005
Loading...

Share This Page