C#哈希表与C#x2B+;散列映射 我比较C++中的下面的代码,C和C(MUNO 2.4)看起来更快。C++代码有什么不对吗?< /P> #include <map> #include <string> #include <iostream> #include <ext/hash_map> #include <boost/any.hpp> int main() { //std::map<long, long> m; // hash_map is a little bit faster __gnu_cxx::hash_map<long, long> m; for( long i = 0; i < 1000000; ++i ) { m[i] = i; } }
一些想法:C#哈希表与C#x2B+;散列映射 我比较C++中的下面的代码,C和C(MUNO 2.4)看起来更快。C++代码有什么不对吗?< /P> #include <map> #include <string> #include <iostream> #include <ext/hash_map> #include <boost/any.hpp> int main() { //std::map<long, long> m; // hash_map is a little bit faster __gnu_cxx::hash_map<long, long> m; for( long i = 0; i < 1000000; ++i ) { m[i] = i; } },c#,c++,C#,C++,一些想法: 你在比较Mono和Boost < Mono和C++ + 使用哪种优化(默认或不设置)设置? < C++和C++版本的初始/默认哈希表大小是什么? 你是否尝试过与其他的C++散列图进行比较,比如? 记住不仅要看实时,还要看实际使用的CPU时间 需要编译C++代码,编译器优化打开,以进行公平的比较。否则,您将苹果与调试构建进行比较——编译器甚至不会尝试发出快速代码 GCC中,这将是>O3标志,开始。你编译了C++代码并优化了吗?也请注意,初始哈希映射大小可能不同。例如,如果C是较大
- 你在比较Mono和Boost < Mono和C++ + 使用哪种优化(默认或不设置)设置? < C++和C++版本的初始/默认哈希表大小是什么? <>你是否尝试过与其他的C++散列图进行比较,比如?
- 记住不仅要看实时,还要看实际使用的CPU时间
<> GCC中,这将是
using System;
using System.Collections;
public int Main()
{
Hashtable m = new Hashtable();
for( long i = 0; i < 1000000; ++i )
{
m[i] = i;
}
}
$ time ./a.out
real 0m1.028s
user 0m0.986s
sys 0m0.041s
$ time mono test.exe
real 0m0.603s
user 0m0.732s
sys 0m0.090s