1

我有一个调用 DLL 的应用程序,它又可能调用另一个 DLL。

当这些二进制文件是 64 位与 32 位时,我的问题是性能下降。

我一直在使用 Elapsed Time 和 CPU Cache Misses 计数器进行分析(AQtime v8.24),但我不明白结果是否有助于我知道该怎么做。

所以我写了一个调用测试DLL的测试.exe,简化了代码。最初,这些工具存在性能下降(64 位版本比 32 位慢四倍),CPU Cache Misses 测试指出了这个例程:

const char* TSimple::get_schema_name( const int schema_number )
{
    char* t_ptr = 0;
    int t_idx;
    for (t_idx = 0; t_idx < 153; t_idx++)
    {
        // THIS ASSIGNMENT IS WHAT WAS SHOWN TO BE A PROBLEM
        bogus_SchemaDef t_def = schema_list[t_idx];
        if (t_def.SchemaNumber == schema_number)
        {
            return (const char*)schema_list[t_idx].SchemaName;
            break;
        }
    }

    return t_ptr;
}

// THIS IS THE bogus_SchemaDef struct:
typedef struct
{
    int SchemaNumber;
    char SchemaName[100];
    char SiteList[100];
} bogus_SchemaDef;

// THIS IS THE schema_list ARRAY (portion):
static bogus_SchemaDef schema_list[] = {
{ 1, "LipUpper", "C000;C003" },
{ 153, "IllDefinedOther", "C420-C424;C760-C765;C767-C768;C770-C775;C778-C779;C809" }
};

所以我把代码改成了这个(消除了对结构实例的赋值):

const char* TSimple::get_schema_name( const int schema_number )
{
    char* t_ptr = 0;
    int t_idx;
    for (t_idx = 0; t_idx < 153; t_idx++)
    {
        //bogus_SchemaDef t_def = schema_list[t_idx];
        //if (t_def.SchemaNumber == schema_number)
        if (schema_list[t_idx].SchemaNumber == schema_number)
        {
            return (const char*)schema_list[t_idx].SchemaName;
            break;
        }
    }

    return t_ptr;
}

重新运行测试,这次 64 位版本比 32 位版本快 36%。伟大的!尽管我不明白为什么这种变化会产生如此大的影响。

但据 AQtime 称,64 位版本的性能仍然比 32 位版本差。

CPU Cache Misses/% Misses
32-bit: 25.79%
64-bit: 83.34%

Elapsed Time/% Time
32-bit: 10.99%
64-bit: 33.95%

我真的需要了解 AQtime 告诉我什么,因为当我将此修改后的测试 DLL 插入我的应用程序调用我的 DLL 然后调用此 DLL 的环境中时,整体性能下降了 30-40%。

我应该注意,当我测试我的应用程序 + DLL 时,我没有调用第二个 DLL,64 位构建的运行速度与 32 位构建一样快或更快。一切都指向对任何第二个 DLL 的调用。

追逐文档让我不知所措......让自己感到困惑......并最终猜测可能会或可能不会产生任何影响的代码更改。

希望得到指导。

4

0 回答 0