Python and STL efficiency

Ray ray_usenet at yahoo.com
Tue Aug 22 19:50:07 EDT 2006


Tim N. van der Leeuw wrote:
> Incidentally, I also have a version compiled with VC++ 6 now... (not
> yet w/VC++ 7) .. Compiled with release-flags and maximum optimization
> for speed, here's the result of VC++ 6:
<snip>

OK, now I'm getting obsessed with this too ;-)

I'm using VC++ Express, I didn't care to tweak the optimizations, I
merely chose the "Release" configuration for the executable. It's
blazing fast, taking only 30+ ms each run.

Here's the code:

int main(){
	DWORD begin = ::GetTickCount();
    vector<string> a;
	string c = "What do you know?";
	string d = "so long...";
	string e = "chicken crosses road";
	string f = "fool";
    for (long int i=0; i<10000 ; ++i){
            a.push_back(c);
            a.push_back(d);
            a.push_back(e);
            a.push_back(f);
    }
    set<string> b(a.begin(), a.end());
    unique_copy(b.begin(), b.end(), ostream_iterator<string>(cout,
"\n"));
	DWORD end = ::GetTickCount();
	cout << "Ends in " << (end - begin) << " ms.";
}

And here's the result:

\TestSTL\release>TestSTL.exe
What do you know?
chicken crosses road
fool
so long...
Ends in 31 ms.

I tried the original version:

int main(){
	DWORD begin = ::GetTickCount();
    vector<string> a;
    for (long int i=0; i<10000 ; ++i){
            a.push_back("What do you know?");
            a.push_back("so long...");
            a.push_back("chicken crosses road");
            a.push_back("fool");
    }
    set<string> b(a.begin(), a.end());
    unique_copy(b.begin(), b.end(), ostream_iterator<string>(cout,
"\n"));
	DWORD end = ::GetTickCount();
	cout << "Ends in " << (end - begin) << " ms.";
}

And the result is only 50% slower:

\TestSTL\release>TestSTL.exe
What do you know?
chicken crosses road
fool
so long...
Ends in 47 ms.




More information about the Python-list mailing list