English 中文(简体)
为什么被困:tr1:没有顺序——地图比土土土土土土土的地图要慢?
原标题:Why is std::tr1::unordered_map slower than a homegrown hash map?

我撰写了一份基本方案,其中将独一无二的病例列入“扼杀和gt”地图。

我使用的是:t:tr1::unordered_map for the ratification, modeld for atomh function and atom equality function。 关键类型实际上是<代码>char*。 http://www.ohchr.org。

然后,我修改了同一法典,以使用一个非常简便的散列表(即由散列的{钥匙,价值}结构,以斜体为指数),其大小和线性碰撞探测力最高。 该方案的速率达到33%。

鉴于我使用tr1:无顺序 我把草原表推上,它从未增长过,而且我正在使用同样的 has和比较常规,什么是tr的:没有顺序——做的地图比最根本的 has地图少50%?

Code for the hash map type I m talking about as "simple" here:

typedef struct dataitem {
    char* item;
    size_t count;
} dataitem_t;

dataitem_t hashtable[HASHTABLE_SIZE] = {{NULL,0}}; // Start off with empty table

void insert(char* item) {
    size_t hash = generate_hash(item);
    size_t firsthash = hash;
    while (true) {
        hash &= HASHTABLE_SIZE_MASK; // Bitmasking effect is hash %= HASHTABLE_SIZE
        if (hashtable[hash].item == NULL) { // Free bucket
            hashtable[hash].item = item;
            hashtable[hash].count = 1;
            break;
        }
        if (strcmp(hashtable[hash].item, item) == 0) { // Not hash collision; same item
            hashtable[hash].count += 1;
            break;
        }
        hash++; // Hash collision.  Move to next bucket (linear probing)
        if (hash == firsthash) {
            // Table is full.  This does not happen because the presizing is correct.
            exit(1);
        }
    }
}
问题回答

我愿回答“A Programmer”。

你的散列图很简单,因为它符合你的需要。 而另一方面,<代码>则:tr1::unordered_map必须履行若干不同的任务,而且无论如何都是良好的。 这要求在所有情况下都采用一种平均业绩办法,因此,在任何特定领域,这种做法永远不会是好的。

哈希集装箱非常特殊,因为有许多执行方式,你选择了开放式补给,而标准部队则对执行者采取et办法。 两者都有不同的取舍,这是标准实际执行的原因之一:在从一个图书馆转到另一个图书馆时,业绩不会发生重大变化。 简单地说明大-奥的复杂性/摊销的复杂性在此还不够。

You say that you instructed the unordered_map as to the number of finals elements, but did you change the load factor ? Chaining is notoriously "bad" (because of the lack of memory locality) in case of collisions, and using a smaller load factor would favor spreading out your elements.

最后,要指出一个不同之处:当你转播你的草图时,情况如何? 通过使用链条,<代码>unordered_map 2. 记忆中的内容不得移动:

  • references to them are still valid (even though the iterators may be invalidated)
  • in case of big or complex objects, there is no invocation of copy constructors

这与简单执行<>/em>形成对照,这将产生O(N)(除非你使用线性重来传播工作,但这肯定不是简单的)。

因此,看来选择<代码>unordered_map是为了使spikes<>>/em>以较低的平均数为代价。

可提供底部分配/>。 具体指派人负责您的用途,并在其中分配其全部记忆(因为你知道将插入多少个目标,而且拨款人可以报告有多少记忆是空洞)。 然后以类似的方式分配节点(简单点数增加)。 它应当改进业绩(有些改进)。

Your "homegrown hash map" is not a hash map at all, it s an intrusive hash set. And that s the reason it s faster. Simple as that.

其实,实际上的侵扰性洗衣机是固定的,但距离最接近。

总体而言,将不在同一光谱上建构件的速度进行比较是不公平的。

如果不确切了解你所衡量的——即目前/经常数据组合的装载系数——的混合业务,就很难解释差异产生在何处。

g++的T1通过链条解决碰撞问题。 这意味着动态分配。 但是,这也使高负荷性能得到提高。

页: 1 或许还有许多事情,在进行之前,你不再检查。 原因可能是贵重地图的速率高于std:tr1::unordered_map

Also, the performance of std::tr1::unordered_map is defined by the implementation, so different implementation would perform differently speed-wise. You can see its implementation and compare it with yours, as that is the first thing you can do, and I believe, that will also answer your question to some extent.

页: 1 我只是假定你的说法是正确的,根据它,我说了上述话。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?