Login  Register

Re: 2D Arrays?

Posted by Ole Peng on May 13, 2008; 2:36am
URL: http://quantlib.414.s1.nabble.com/2D-Arrays-tp5941p5942.html


I am no expert, so barely qualify to make the kind of sarcastic comments I make anyway...
But, I know quite a few people who refuse to use to use either STD/STL or boost for basic
containers or performance sensitive program bits in general. Instead it is "not too difficult" to
write your own basic types, allowing you to control such things as what your container is
ultimately mapped to, or how you want to implement copy, assignment etc... At the same
time you can twist your containers such that they are still supported with most regular STL
algorithms."not too difficult" is a euphemism, I know. the best thing is to pick up some classes
from someone and then take it from there.

there are apparently some really shitty features in boost that you just don't want to have in
your software at all.... what about blitz? that any good?

----- Original Message ----
From: Luigi Ballabio <[hidden email]>
To: caffeine <[hidden email]>
Cc: [hidden email]
Sent: Monday, May 12, 2008 12:35:45 PM
Subject: Re: [Quantlib-users] 2D Arrays?

On Mon, 2008-05-12 at 08:49 -0700, caffeine wrote:
> I see that I was too slow on the "it's too slow" response.  :-)
>
> Do you have any proof that a compiler will inline std::vector calls into raw
> C array accesses?  If it were true, I would be ecstatic, but I don't believe
> it for a second.

Not "proof" as such---results will probably depend on context. But on my
machine, compiling with g++ 4.2.3 and with full optimization turned on
(i.e., -O3), the two following programs run in about the same time. It
seems pretty good evidence that, at least in this case, operator[] is
inlined.

However, if allocation is moved inside the outer loop, the vector
program runs slower. Either vector creation is slower, or adding the
allocation inside the loop changes the inlining policy---your guess is
as good as mine.

Luigi


-------------------------
test1.cpp
-------------------------
#include <vector>

int main() {
    std::vector<double> v(10000);
    for (int j=0; j<10000; ++j) {
        for (int i=0; i<10000; ++i)
            v[i] = 42.0;
        double x;
        for (int i=0; i<10000; ++i)
            x = v[i];
    }
    return 0;
}

-------------------------
test2.cpp
-------------------------
int main() {
    double* v = new double[10000];
    for (int j=0; j<10000; ++j) {
        for (int i=0; i<10000; ++i)
            v[i] = 42.0;
        double x;
        for (int i=0; i<10000; ++i)
            x = v[i];
    }
    delete[] v;
    return 0;
}



--

There are no rules of architecture for a castle in the clouds.
-- Gilbert K. Chesterton



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users