Its only noticeably slower on really large arrays, like hundred millions of elements, probably because CArray doing unnecessary stuff like zeroing memory before using it.
Alexander Fedorov
Posts
-
MFC vs STL performance test -
MFC vs STL performance testGood point. Exception handling actually does not add anithing to the timing, because its just 1 large function that wrapped in it. I just was wondering why I cannot allocate 500M array while vectors.max_siz says it can do over 1G so basically its a leftover from some debugging. MFC CArray is actually only container that I found is 4-5 times slower than STL vector with or without try-catch block. Maybe if I add array random access to the test MFC will be winning?
-
MFC vs STL performance testWhat I asked is to verify if my code is correct and maybe suggest how to make it more valid. I still remember claims how "highly portable", "highly standard" and "very fast" STL was back in 1999, this is really not what I was asking.
-
MFC vs STL performance testExactly why? I can't believe I am violating something.
-
MFC vs STL performance testHi guys, I did some performance comparison between MFC and STL containers and I think maybe it could evolve into an article here at Codeproject. Please have a look at my code and suggest some improvements to make comparison more valid. So far I found that STL still sucks big time even after 10 or 15 years of polishing (and neglecting of MFC) in VS2012. Following is complete source code, just drop it into console project with MFC support, compile and run in Release mode.
// MFCvsSTL.cpp : Performance comparison between MFC and STL containers // (c) Alex Fedorov http:://alexf.name 2013 #include "stdafx.h" #include "MFCvsSTL.h" // nothing special here #include <unordered_map> #include <map> #include <vector> #include <list> #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; // typedef map<DWORD, void*> stlmap; typedef unordered_map<DWORD, void*> stlmap; int stlMap(int nCount) { int nSize = (int)(1.2 * (float)nCount); stlmap a(nSize); // unordered_map <DWORD, void*> a(nSize); for( int i = 0; i < nCount; ++i ) { a[ i ] = (void *) i; } stlmap::iterator iter; for( int j = 0; j < nCount; ++j ) { iter = a.find( ( abs( rand() * j ) % nCount ) ); } return 1; } int mfcMap(int nCount) { int nSize = (int)(1.2 * (float)nCount); // CMapWordToPtr a; CMap<DWORD, DWORD, void*, void*> a; a.InitHashTable( nSize ); for( int i = 0; i < nCount; ++i ) { a[ i ] = (void *) i; } void * val; for( int j = 0; j < nCount; ++j ) { a.Lookup( ( abs( rand() * j ) % nCount ), val ); } return 0; } int stlArray(int nCount) { vector <int> bigarray; int nMs = bigarray.max_size(); try { bigarray.reserve(nCount); } catch (...) { CString str; str.Format(_T("Memory allocation error trying to reserve %d elements. vector.max_size=%d\r\n"), nCount, nMs); _tprintf(str); return 0; } for(int k = 0; k < nCount; ++k) { bigarray.push_back(k); // bigarray[k] = k; } int ret = bigarray.size(); return ret; } int mfcArray(int nCount) { // CArray<int,int> arr; // OCArray<int> arr; CUIntArray arr; arr.SetSize(0, nCount); for(int k = 0; k < nCount; ++k) { arr.Add(k); // arr[k] = k; } int ret = arr.GetCount(); return ret; } int mfcList(int nCount) { CList<int, int> a; for(int k = 0; k < nCount; ++k) { a.AddHead(
-
CMapWordToPtr in STL?Thanks for suggestion. I am user number 10 at this site but not a frequent visitor.
-
CMapWordToPtr in STL?Hi guys, quick question: What would be an equvalent of CMapWordToPtr in modern STL? Is it unordered_map or somethig else is better?
-
VC++ debugging with latest Avira AntivirI has Visual Studio 2008 on my Windowx XP machine and this entire Windows installation was later converted into VHD instance to run inside Virtual PC on Windows 7.64. Everytihng was working fine until recently. I am not sure what I changed, maybe nothing at all, but now I am unable to debug most of compiled projects inside this virtual Windows. Visual Studio reports that debugged application is unable to initialize properly or throwing some weird exceptions, sometimes applications starts but then its unable to call some standard Windows APIs like returns 0 from InternetOpen function. Compiler and linker by itself seems to work properly, if I run compiled applications from same virtual machine, they work fine, only problem I see is when I try to debug something using IDE inside Virtual PC. I tried to roll back VHD file to the state when everything was working but it does not help, so I guess its a virtualization problem. Any thoughts how could I fix this? Update: Never mind, it seems to have nothing to do with virtualization, its a bug in latest Avira Antivir and is described here: http://www.avira.com/de/support-for-free-faq-detail/faqid/805[^] and here in English: https://forum.avira.com/wbb/index.php?page=Thread&postID=1031803[^]
-
Codeproject hacked?I just get several emails in my inbox about some article that was presumably submitted by me and that people are "astonished" by the bad quality of the article and it does not meet the standards and got deleted. Problem is that I can not remember if I submitted any such articles and for sure I did not submitted ANY articles in the past 5 or 7 years. So something stange is going on here. Article itself is not available anymore so I could not see if I really wrote it or not and when it was submitted. What should I do?
-
How to inject javascript into webbrowser controlRight, now I get it, but how do I inject something that can write into the page without erasing it? Should I override some event like DocumentComplete? Can I make loaded page to get "busy" again and inject something then?
-
How to inject javascript into webbrowser controlNo, I dont think so. This page will say "Hello world!" not just "world!":
<html> <body> Hello <script type="text/javascript"> document.write('world!'); </script> </body> </html>
But if I inject similar code into control, it will just say "world!". This happens because script is deferred, but this is what I am trying to do, I need script to be able to execute but not to erase previous content. -
How to inject javascript into webbrowser controlHello, I have a dialog based MFC application with embedded webbrowser control. I need to load an url and then inject my javascript when page is loaded. I am able to do this by using insertAdjacentHTML function or pasteHTML (with regions) and injecting deferred script. But the problem is when this injected script is trying to do document.write into the page, it seems to erase all content of the document. What could be a problem there? Also, injected script does not work if I inject script only, it is always necessary to add some "garbade" before script, some extra characters. This is my source code:
long rs = m_web01.get_ReadyState(); if (4 == rs) { MSHTML::IHTMLDocument2Ptr spDoc2 = m_web01.get_Document(); MSHTML::IHTMLBodyElementPtr spBody = spDoc2->body; MSHTML::IHTMLElementPtr spBodElem = spBody; spBodElem->insertAdjacentHTML(_bstr_t("beforeEnd"), _bstr_t(strInjection)); }
Also, there is another problem, sometimes webbrowser just hangs when trying to download a page, for example google finance homepage page will hang it almost for sure. There is an article in KB saying that there is a problem with setting focus if control is embedded into the formview, but I could not find an universal solution, my control embedded into property page, so how do I handle this?