Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
patch : from std::map replace to hashmap
Loaden:
If use -O0 like Code-Completion plugins, here are some test data:
--- Code: ---stdMap 1 : 4282
stdMap 2 : 4265
stdMap 3 : 4281
stdMap 4 : 4266
stdMap 5 : 4281
---------------
hashMap 1 : 2969
hashMap 2 : 2969
hashMap 3 : 2969
hashMap 4 : 2984
hashMap 5 : 2969
---------------
stdMap2 1 : 5234
stdMap2 2 : 5234
stdMap2 3 : 5235
stdMap2 4 : 5234
stdMap2 5 : 5250
---------------
hashMap2 1 : 3266
hashMap2 2 : 3265
hashMap2 3 : 3266
hashMap2 4 : 3266
hashMap2 5 : 3265
Process returned 0 (0x0) execution time : 78.906 s
Press any key to continue.
--- End code ---
ollydbg:
--- Quote from: Loaden on March 22, 2010, 01:55:27 am ---If use -O0 like Code-Completion plugins, here are some test data:
--- Code: ---stdMap 1 : 4282
stdMap 2 : 4265
stdMap 3 : 4281
stdMap 4 : 4266
stdMap 5 : 4281
---------------
hashMap 1 : 2969
hashMap 2 : 2969
hashMap 3 : 2969
hashMap 4 : 2984
hashMap 5 : 2969
---------------
stdMap2 1 : 5234
stdMap2 2 : 5234
stdMap2 3 : 5235
stdMap2 4 : 5234
stdMap2 5 : 5250
---------------
hashMap2 1 : 3266
hashMap2 2 : 3265
hashMap2 3 : 3266
hashMap2 4 : 3266
hashMap2 5 : 3265
Process returned 0 (0x0) execution time : 78.906 s
Press any key to continue.
--- End code ---
--- End quote ---
so, the xxx2 version is ANSI version(std::string) and the other is UNICODE version(wxString).
For std-map, UNICODE is better.
For hash-map, ANSI is better.
Oh, wait, I think you don't defined the UNICODE macros, so all the string type is ANSI.
Loaden:
If you use only seven replacement rules:
No Optimization (-O0):
--- Code: ---stdMap 1 : 3671
stdMap 2 : 3657
stdMap 3 : 3672
stdMap 4 : 3671
stdMap 5 : 3657
---------------
hashMap 1 : 2953
hashMap 2 : 2953
hashMap 3 : 2953
hashMap 4 : 2953
hashMap 5 : 2938
---------------
stdMap2 1 : 4234
stdMap2 2 : 4234
stdMap2 3 : 4235
stdMap2 4 : 4234
stdMap2 5 : 4235
---------------
hashMap2 1 : 3156
hashMap2 2 : 3172
hashMap2 3 : 3172
hashMap2 4 : 3171
hashMap2 5 : 3157
Process returned 0 (0x0) execution time : 70.281 s
Press any key to continue.
--- End code ---
Optimization (-O2):
--- Code: ---stdMap 1 : 2156
stdMap 2 : 2156
stdMap 3 : 2156
stdMap 4 : 2156
stdMap 5 : 2157
---------------
hashMap 1 : 2296
hashMap 2 : 2297
hashMap 3 : 2297
hashMap 4 : 2281
hashMap 5 : 2297
---------------
stdMap2 1 : 3047
stdMap2 2 : 3047
stdMap2 3 : 3047
stdMap2 4 : 3031
stdMap2 5 : 3047
---------------
hashMap2 1 : 2391
hashMap2 2 : 2406
hashMap2 3 : 2406
hashMap2 4 : 2391
hashMap2 5 : 2406
Process returned 0 (0x0) execution time : 49.734 s
Press any key to continue.
--- End code ---
ollydbg:
I suggest changing the variable names. see the code below:
--- Code: ---#include <iostream>
#include <map>
#include <string>
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
#include <wx/hashmap.h>
#include <wx/string.h>
#include <wx/timer.h>
namespace std
{
using namespace __gnu_cxx;
}
namespace __gnu_cxx
{
template<> struct hash< std::string >
{
size_t operator()( const std::string& x ) const
{
return hash< const char* >()( x.c_str() );
}
};
}
//namespace __gnu_cxx
//{
//template<> struct hash< wxString >
//{
// size_t operator()( const wxString& x ) const
// {
// return hash< const wxChar* >()( x.c_str() );
// }
//};
//}
WX_DECLARE_STRING_HASH_MAP(wxString, wxHashString);
int main()
{
wxHashString wxHashMapwxString;
wxHashMapwxString[_T("_GLIBCXX_STD")] = _T("std");
wxHashMapwxString[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE")] = _T("+namespace");
wxHashMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE")] = _T("+namespace");
wxHashMapwxString[_T("_GLIBCXX_END_NESTED_NAMESPACE")] = _T("}");
wxHashMapwxString[_T("_GLIBCXX_END_NAMESPACE")] = _T("}");
wxHashMapwxString[_T("_GLIBCXX_END_NAMESPACE_TR1")] = _T("}");
wxHashMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE_TR1")] = _T("-namespace tr1 {");
wxHashMapwxString[_T("_GLIBCXX_STD2")] = _T("2std");
wxHashMapwxString[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE2")] = _T("2+namespace");
wxHashMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE2")] = _T("2+namespace");
wxHashMapwxString[_T("_GLIBCXX_END_NESTED_NAMESPACE2")] = _T("2}");
wxHashMapwxString[_T("_GLIBCXX_END_NAMESPACE2")] = _T("2}");
wxHashMapwxString[_T("_GLIBCXX_END_NAMESPACE_TR12")] = _T("2}");
wxHashMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("2-namespace tr1 {");
wxHashMapwxString[_T("_XXGLIBCXX_END_NAMESPACE_TR12")] = _T("X2}");
wxHashMapwxString[_T("_XXGLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("X2-namespace tr1 {");
std::map<wxString, wxString> stdMapwxString;
stdMapwxString[_T("_GLIBCXX_STD")] = _T("std");
stdMapwxString[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE")] = _T("+namespace");
stdMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE")] = _T("+namespace");
stdMapwxString[_T("_GLIBCXX_END_NESTED_NAMESPACE")] = _T("}");
stdMapwxString[_T("_GLIBCXX_END_NAMESPACE")] = _T("}");
stdMapwxString[_T("_GLIBCXX_END_NAMESPACE_TR1")] = _T("}");
stdMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE_TR1")] = _T("-namespace tr1 {");
stdMapwxString[_T("_GLIBCXX_STD2")] = _T("2std");
stdMapwxString[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE2")] = _T("2+namespace");
stdMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE2")] = _T("2+namespace");
stdMapwxString[_T("_GLIBCXX_END_NESTED_NAMESPACE2")] = _T("2}");
stdMapwxString[_T("_GLIBCXX_END_NAMESPACE2")] = _T("2}");
stdMapwxString[_T("_GLIBCXX_END_NAMESPACE_TR12")] = _T("2}");
stdMapwxString[_T("_GLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("2-namespace tr1 {");
stdMapwxString[_T("_XXGLIBCXX_END_NAMESPACE_TR12")] = _T("X2}");
stdMapwxString[_T("_XXGLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("X2-namespace tr1 {");
std::hash_map<std::string, std::string> stdHashMapstdString;
stdHashMapstdString["_GLIBCXX_STD"] = "std";
stdHashMapstdString["_GLIBCXX_BEGIN_NESTED_NAMESPACE"] = "+namespace";
stdHashMapstdString["_GLIBCXX_BEGIN_NAMESPACE"] = "+namespace";
stdHashMapstdString["_GLIBCXX_END_NESTED_NAMESPACE"] = "}";
stdHashMapstdString["_GLIBCXX_END_NAMESPACE"] = "}";
stdHashMapstdString["_GLIBCXX_END_NAMESPACE_TR1"] = "}";
stdHashMapstdString["_GLIBCXX_BEGIN_NAMESPACE_TR1"] = "-namespace tr1 {";
stdHashMapstdString["_GLIBCXX_STD2"] = "2std";
stdHashMapstdString["_GLIBCXX_BEGIN_NESTED_NAMESPACE2"] = "2+namespace";
stdHashMapstdString["_GLIBCXX_BEGIN_NAMESPACE2"] = "2+namespace";
stdHashMapstdString["_GLIBCXX_END_NESTED_NAMESPACE2"] = "2}";
stdHashMapstdString["_GLIBCXX_END_NAMESPACE2"] = "2}";
stdHashMapstdString["_GLIBCXX_END_NAMESPACE_TR12"] = "2}";
stdHashMapstdString["_GLIBCXX_BEGIN_NAMESPACE_TR12"] = "2-namespace tr1 {";
stdHashMapstdString["_XXGLIBCXX_END_NAMESPACE_TR12"] = "X2}";
stdHashMapstdString["_XXGLIBCXX_BEGIN_NAMESPACE_TR12"] = "X2-namespace tr1 {";
std::map<std::string, std::string> stdMapstdString;
stdMapstdString["_GLIBCXX_STD"] = "std";
stdMapstdString["_GLIBCXX_BEGIN_NESTED_NAMESPACE"] = "+namespace";
stdMapstdString["_GLIBCXX_BEGIN_NAMESPACE"] = "+namespace";
stdMapstdString["_GLIBCXX_END_NESTED_NAMESPACE"] = "}";
stdMapstdString["_GLIBCXX_END_NAMESPACE"] = "}";
stdMapstdString["_GLIBCXX_END_NAMESPACE_TR1"] = "}";
stdMapstdString["_GLIBCXX_BEGIN_NAMESPACE_TR1"] = "-namespace tr1 {";
stdMapstdString["_GLIBCXX_STD2"] = "2std";
stdMapstdString["_GLIBCXX_BEGIN_NESTED_NAMESPACE2"] = "2+namespace";
stdMapstdString["_GLIBCXX_BEGIN_NAMESPACE2"] = "2+namespace";
stdMapstdString["_GLIBCXX_END_NESTED_NAMESPACE2"] = "2}";
stdMapstdString["_GLIBCXX_END_NAMESPACE2"] = "2}";
stdMapstdString["_GLIBCXX_END_NAMESPACE_TR12"] = "2}";
stdMapstdString["_GLIBCXX_BEGIN_NAMESPACE_TR12"] = "2-namespace tr1 {";
stdMapstdString["_XXGLIBCXX_END_NAMESPACE_TR12"] = "X2}";
stdMapstdString["_XXGLIBCXX_BEGIN_NAMESPACE_TR12"] = "X2-namespace tr1 {";
for (int i = 0; i < 5; ++i)
{
wxStartTimer();
for (int j = 0; j < 10000000; ++j) stdMapwxString.find(_T("testfindkey"));
std::cout << "stdMapwxString " << i + 1 << " : " << wxGetElapsedTime() << std::endl;
}
std::cout << "\n---------------\n" << std::endl;
for (int i = 0; i < 5; ++i)
{
wxStartTimer();
for (int j = 0; j < 10000000; ++j) wxHashMapwxString.find(_T("testfindkey"));
std::cout << "wxHashMapwxString " << i + 1 << " : " << wxGetElapsedTime() << std::endl;
}
std::cout << "\n---------------\n" << std::endl;
for (int i = 0; i < 5; ++i)
{
wxStartTimer();
for (int j = 0; j < 10000000; ++j) stdMapstdString.find("testfindkey");
std::cout << "stdMapstdString " << i + 1 << " : " << wxGetElapsedTime() << std::endl;
}
std::cout << "\n---------------\n" << std::endl;
for (int i = 0; i < 5; ++i)
{
wxStartTimer();
for (int j = 0; j < 10000000; ++j) stdHashMapstdString.find("testfindkey");
std::cout << "stdHashMapstdString " << i + 1 << " : " << wxGetElapsedTime() << std::endl;
}
return 0;
}
--- End code ---
And the result is here, I built this project with -O2 :
--- Code: ---stdMapwxString 1 : 3094
stdMapwxString 2 : 3094
stdMapwxString 3 : 3094
stdMapwxString 4 : 3109
stdMapwxString 5 : 3110
---------------
wxHashMapwxString 1 : 3296
wxHashMapwxString 2 : 3313
wxHashMapwxString 3 : 3297
wxHashMapwxString 4 : 3312
wxHashMapwxString 5 : 3297
---------------
stdMapstdString 1 : 4719
stdMapstdString 2 : 4734
stdMapstdString 3 : 4766
stdMapstdString 4 : 4734
stdMapstdString 5 : 4735
---------------
stdHashMapstdString 1 : 3515
stdHashMapstdString 2 : 3500
stdHashMapstdString 3 : 3516
stdHashMapstdString 4 : 3516
stdHashMapstdString 5 : 3515
Process returned 0 (0x0) execution time : 73.344 s
Press any key to continue.
--- End code ---
So, you can see:
--- Quote ---stdMapwxString 1 : 3094
stdMapwxString 2 : 3094
stdMapwxString 3 : 3094
stdMapwxString 4 : 3109
stdMapwxString 5 : 3110
---------------
wxHashMapwxString 1 : 3296
wxHashMapwxString 2 : 3313
wxHashMapwxString 3 : 3297
wxHashMapwxString 4 : 3312
wxHashMapwxString 5 : 3297
--- End quote ---
Optimized stdMap is better than wxHashMap.
Loaden:
Please look at GNU's hash_map test results. (-O2)
--- Code: ---#include <iostream>
#include <map>
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
#include <wx/hashmap.h>
#include <wx/string.h>
#include <wx/timer.h>
namespace std
{
using namespace __gnu_cxx;
}
namespace __gnu_cxx
{
template<> struct hash< wxString >
{
size_t operator()( const wxString& x ) const
{
unsigned long __h = 0;
const wxChar* p = x.wx_str();
size_t size = x.size();
while (size) __h = 5 * __h + p[--size];
return size_t(__h);
}
};
}
WX_DECLARE_STRING_HASH_MAP(wxString, wxHashString);
int main()
{
std::hash_map<wxString, wxString> hashMap;
hashMap[_T("_GLIBCXX_STD")] = _T("std");
hashMap[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE")] = _T("+namespace");
hashMap[_T("_GLIBCXX_BEGIN_NAMESPACE")] = _T("+namespace");
hashMap[_T("_GLIBCXX_END_NESTED_NAMESPACE")] = _T("}");
hashMap[_T("_GLIBCXX_END_NAMESPACE")] = _T("}");
hashMap[_T("_GLIBCXX_END_NAMESPACE_TR1")] = _T("}");
hashMap[_T("_GLIBCXX_BEGIN_NAMESPACE_TR1")] = _T("-namespace tr1 {");
// hashMap[_T("_GLIBCXX_STD2")] = _T("2std");
// hashMap[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE2")] = _T("2+namespace");
// hashMap[_T("_GLIBCXX_BEGIN_NAMESPACE2")] = _T("2+namespace");
// hashMap[_T("_GLIBCXX_END_NESTED_NAMESPACE2")] = _T("2}");
// hashMap[_T("_GLIBCXX_END_NAMESPACE2")] = _T("2}");
// hashMap[_T("_GLIBCXX_END_NAMESPACE_TR12")] = _T("2}");
// hashMap[_T("_GLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("2-namespace tr1 {");
// hashMap[_T("_XXGLIBCXX_END_NAMESPACE_TR12")] = _T("X2}");
// hashMap[_T("_XXGLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("X2-namespace tr1 {");
std::map<wxString, wxString> stdMap;
stdMap[_T("_GLIBCXX_STD")] = _T("std");
stdMap[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE")] = _T("+namespace");
stdMap[_T("_GLIBCXX_BEGIN_NAMESPACE")] = _T("+namespace");
stdMap[_T("_GLIBCXX_END_NESTED_NAMESPACE")] = _T("}");
stdMap[_T("_GLIBCXX_END_NAMESPACE")] = _T("}");
stdMap[_T("_GLIBCXX_END_NAMESPACE_TR1")] = _T("}");
stdMap[_T("_GLIBCXX_BEGIN_NAMESPACE_TR1")] = _T("-namespace tr1 {");
// stdMap[_T("_GLIBCXX_STD2")] = _T("2std");
// stdMap[_T("_GLIBCXX_BEGIN_NESTED_NAMESPACE2")] = _T("2+namespace");
// stdMap[_T("_GLIBCXX_BEGIN_NAMESPACE2")] = _T("2+namespace");
// stdMap[_T("_GLIBCXX_END_NESTED_NAMESPACE2")] = _T("2}");
// stdMap[_T("_GLIBCXX_END_NAMESPACE2")] = _T("2}");
// stdMap[_T("_GLIBCXX_END_NAMESPACE_TR12")] = _T("2}");
// stdMap[_T("_GLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("2-namespace tr1 {");
// stdMap[_T("_XXGLIBCXX_END_NAMESPACE_TR12")] = _T("X2}");
// stdMap[_T("_XXGLIBCXX_BEGIN_NAMESPACE_TR12")] = _T("X2-namespace tr1 {");
for (int i = 0; i < 5; ++i)
{
wxStartTimer();
for (int j = 0; j < 10000000; ++j) stdMap.find(_T("testfindkey"));
std::cout << "stdMap " << i + 1 << " : " << wxGetElapsedTime() << std::endl;
}
std::cout << "\n---------------\n" << std::endl;
for (int i = 0; i < 5; ++i)
{
wxStartTimer();
for (int j = 0; j < 10000000; ++j) hashMap.find(_T("testfindkey"));
std::cout << "hashMap " << i + 1 << " : " << wxGetElapsedTime() << std::endl;
}
return 0;
}
--- End code ---
--- Code: ---stdMap 1 : 2203
stdMap 2 : 2188
stdMap 3 : 2203
stdMap 4 : 2203
stdMap 5 : 2203
---------------
hashMap 1 : 2078
hashMap 2 : 2094
hashMap 3 : 2078
hashMap 4 : 2078
hashMap 5 : 2078
Process returned 0 (0x0) execution time : 21.484 s
Press any key to continue.
--- End code ---
If changed TO 16 replace rules :
--- Code: ---stdMap 1 : 2250
stdMap 2 : 2250
stdMap 3 : 2250
stdMap 4 : 2250
stdMap 5 : 2265
---------------
hashMap 1 : 2031
hashMap 2 : 2047
hashMap 3 : 2047
hashMap 4 : 2031
hashMap 5 : 2032
Process returned 0 (0x0) execution time : 21.672 s
Press any key to continue.
--- End code ---
NO OPTI, 16 replacement: (-O0)
--- Code: ---stdMap 1 : 4281
stdMap 2 : 4282
stdMap 3 : 4281
stdMap 4 : 4281
stdMap 5 : 4297
---------------
hashMap 1 : 3203
hashMap 2 : 3203
hashMap 3 : 3219
hashMap 4 : 3203
hashMap 5 : 3203
Process returned 0 (0x0) execution time : 37.609 s
Press any key to continue.
--- End code ---
OPTI(-O2), 9 replacement:
--- Code: ---stdMap 1 : 2235
stdMap 2 : 2234
stdMap 3 : 2219
stdMap 4 : 2234
stdMap 5 : 2219
---------------
hashMap 1 : 2047
hashMap 2 : 2031
hashMap 3 : 2047
hashMap 4 : 2031
hashMap 5 : 2031
Process returned 0 (0x0) execution time : 21.609 s
Press any key to continue.
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version